forked from micasense/imageprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotutils.py
More file actions
116 lines (104 loc) · 4.25 KB
/
Copy pathplotutils.py
File metadata and controls
116 lines (104 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python
# coding: utf-8
"""
MicaSense Plotting Utilities
Copyright 2017 MicaSense, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.mplot3d import Axes3D
def plotwithcolorbar(img, title=None, figsize=None, vmin=None, vmax=None):
''' Plot an image with a colorbar '''
fig, axis = plt.subplots(1, 1, figsize=figsize)
rad2 = axis.imshow(img, vmin=vmin, vmax=vmax)
axis.set_title(title)
divider = make_axes_locatable(axis)
cax = divider.append_axes("right", size="3%", pad=0.05)
fig.colorbar(rad2, cax=cax)
plt.tight_layout()
plt.show()
return fig, axis
def subplotwithcolorbar(rows, cols, images, titles=None, figsize=None):
''' Plot a set of images in subplots '''
fig, axes = plt.subplots(rows, cols, figsize=figsize)
for i in range(cols*rows):
column = int(i%cols)
row = int(i/cols)
if i < len(images):
rad = axes[row][column].imshow(images[i])
if titles is not None:
axes[row][column].set_title(titles[i])
divider = make_axes_locatable(axes[row][column])
cax = divider.append_axes("right", size="3%", pad=0.05)
fig.colorbar(rad, cax=cax)
else:
axes[row, column].axis('off')
plt.tight_layout()
plt.show()
return fig, axes
def plot_overlay_withcolorbar(imgbase, imgcolor, title=None, figsize=None, vmin=None, vmax=None, overlay_alpha=1.0):
''' Plot an image with a colorbar '''
fig, axis = plt.subplots(1, 1, figsize=figsize)
base = axis.imshow(imgbase)
rad2 = axis.imshow(imgcolor, vmin=vmin, vmax=vmax, alpha=overlay_alpha)
axis.set_title(title)
divider = make_axes_locatable(axis)
cax = divider.append_axes("right", size="3%", pad=0.05)
fig.colorbar(rad2, cax=cax)
plt.tight_layout()
plt.show()
return fig, axis
def subplot(rows, cols, images, titles=None, figsize=None):
''' Plot a set of images in subplots '''
fig, axes = plt.subplots(rows, cols, figsize=figsize)
for i in range(cols*rows):
column = int(i%cols)
row = int(i/cols)
if i < len(images):
rad = axes[row][column].imshow(images[i])
if titles is not None:
axes[row][column].set_title(titles[i])
else:
axes[row, column].axis('off')
plt.tight_layout()
plt.show()
return fig, axes
def colormap(cmap):
''' Set the defalut plotting colormap
Could be one of 'gray, viridis, plasma, inferno, magma, nipy_spectral'
'''
plt.set_cmap(cmap)
import numpy as np
def plot_ned_vector3d(x,y,z, u=0,v=0,w=0, title=None, figsize=(8,5)):
'''Create a 3d plot of a North-East-Down vector. XYZ is the (tip of the) vector,
uvw is the base location of the vector '''
fig = plt.figure(figsize=figsize)
ax = fig.gca(projection='3d')
ax.quiver(u, v, w, x, y, z, color='r')
ax.quiver(u, v, w, x, y, 0, color='b')
ax.quiver(x, y, 0, 0, 0, z, color='g')
ax.legend()
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
ax.set_zlim([0,1])
ax.set_xlabel("West - East")
ax.set_ylabel("South - North")
if title is not None:
plt.title(title)
plt.tight_layout()
plt.show()
return fig,ax