Skip to content

Commit 2013d0a

Browse files
authored
Merge pull request #28 from wx4stg/plotpointskw
use keyword arguments for plot_points and plot_3d_grid
2 parents f5e2513 + e39a852 commit 2013d0a

1 file changed

Lines changed: 47 additions & 17 deletions

File tree

pyxlma/plot/xlma_plot_feature.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,48 +57,78 @@ def setup_hist(lon_data, lat_data, alt_data, time_data,
5757

5858

5959
def plot_points(bk_plot, lon_data, lat_data, alt_data, time_data,
60-
plot_cmap, plot_s, plot_vmin, plot_vmax, plot_c, edge_color='face', edge_width=0):
60+
plot_cmap=None, plot_s=None, plot_vmin=None, plot_vmax=None, plot_c=None, edge_color='face',
61+
edge_width=0, add_to_histogram=True, **kwargs):
6162
"""
6263
Plot scatter points on an existing bk_plot object given x,y,z,t for each
6364
and defined plotting colormaps and ranges
6465
"""
66+
67+
# before **kwargs was added to the function call, the following arguments
68+
# were specified as keywords separately. This allows backwards compatibility:
69+
if plot_cmap is None:
70+
plot_cmap = kwargs.pop('cmap', kwargs.pop('plot_cmap', None))
71+
if plot_s is None:
72+
plot_s = kwargs.pop('s', kwargs.pop('plot_s', None))
73+
if plot_vmin is None:
74+
plot_vmin = kwargs.pop('vmin', kwargs.pop('plot_vmin', None))
75+
if plot_vmax is None:
76+
plot_vmax = kwargs.pop('vmax', kwargs.pop('plot_vmax', None))
77+
if plot_c is None:
78+
plot_c = kwargs.pop('c', kwargs.pop('plot_c', None))
79+
if edge_color == 'face':
80+
edge_color = kwargs.pop('edgecolors', kwargs.pop('edge_color', 'face'))
81+
if edge_width == 0:
82+
edge_width = kwargs.pop('linewidths', kwargs.pop('edge_width', 0))
83+
6584
art_plan = bk_plot.ax_plan.scatter(lon_data, lat_data,
6685
c=plot_c,vmin=plot_vmin, vmax=plot_vmax, cmap=plot_cmap,
67-
s=plot_s,marker='o', linewidths=edge_width, edgecolors=edge_color)
86+
s=plot_s,marker='o', linewidths=edge_width, edgecolors=edge_color, **kwargs)
6887
art_th = bk_plot.ax_th.scatter(time_data, alt_data,
6988
c=plot_c,vmin=plot_vmin, vmax=plot_vmax, cmap=plot_cmap,
70-
s=plot_s,marker='o', linewidths=edge_width, edgecolors=edge_color)
89+
s=plot_s,marker='o', linewidths=edge_width, edgecolors=edge_color, **kwargs)
7190
art_lon = bk_plot.ax_lon.scatter(lon_data, alt_data,
7291
c=plot_c,vmin=plot_vmin, vmax=plot_vmax, cmap=plot_cmap,
73-
s=plot_s,marker='o', linewidths=edge_width, edgecolors=edge_color)
92+
s=plot_s,marker='o', linewidths=edge_width, edgecolors=edge_color, **kwargs)
7493
art_lat = bk_plot.ax_lat.scatter(alt_data, lat_data,
7594
c=plot_c,vmin=plot_vmin, vmax=plot_vmax, cmap=plot_cmap,
76-
s=plot_s,marker='o', linewidths=edge_width, edgecolors=edge_color)
77-
cnt, bins, art_hist = bk_plot.ax_hist.hist(alt_data, orientation='horizontal',
78-
density=True, bins=80, range=(0, 20), color='black')
79-
art_txt = plt.text(0.25, 0.10, str(len(alt_data)) + ' src',
80-
fontsize='small', horizontalalignment='left',
81-
verticalalignment='center',transform=bk_plot.ax_hist.transAxes)
95+
s=plot_s,marker='o', linewidths=edge_width, edgecolors=edge_color, **kwargs)
8296
art_out = [art_plan, art_th, art_lon, art_lat, art_txt]
83-
# art_hist is a tuple of patch objects. Make it a flat list of artists
84-
art_out.extend(art_hist)
97+
98+
if add_to_histogram:
99+
cnt, bins, art_hist = bk_plot.ax_hist.hist(alt_data, orientation='horizontal',
100+
density=True, bins=80, range=(0, 20), color='black')
101+
art_txt = plt.text(0.25, 0.10, str(len(alt_data)) + ' src',
102+
fontsize='small', horizontalalignment='left',
103+
verticalalignment='center',transform=bk_plot.ax_hist.transAxes)
104+
# art_hist is a tuple of patch objects. Make it a flat list of artists
105+
art_out.extend(art_hist)
85106
return art_out
86107

87108
def plot_3d_grid(bk_plot, xedges, yedges, zedges, tedges,
88109
alt_lon, alt_lat, alt_time, lat_lon,
89-
alt_data, plot_cmap):
110+
alt_data, plot_cmap=None, **kwargs):
90111
"""
91112
Plot gridded fields on an existing bk_plot given x,y,z,t grids and
92113
respective grid edges
114+
115+
In previous versions, 'plot_cmap' was required positional argument, this now defaults to None/matplotlib default unless overridden
116+
Before the addition of **kwargs, 'vmin' was hardcoded to 0. This allows the user to specify a vmin in **kwargs, but maintain
117+
backwards compatibility with assuming a vmin of 0 if no vmin is provided
118+
93119
"""
120+
121+
plot_cmap = kwargs.pop('cmap', kwargs.pop('plot_cmap', None))
122+
plot_vmin = kwargs.pop('vmin', 0)
123+
94124
alt_lon[alt_lon==0]=np.nan
95125
alt_lat[alt_lat==0]=np.nan
96126
lat_lon[lat_lon==0]=np.nan
97127
alt_time[alt_time==0]=np.nan
98-
bk_plot.ax_lon.pcolormesh( xedges, zedges, alt_lon.T, cmap=plot_cmap, vmin=0)
99-
bk_plot.ax_lat.pcolormesh( zedges, yedges, alt_lat.T, cmap=plot_cmap, vmin=0)
100-
bk_plot.ax_plan.pcolormesh(xedges, yedges, lat_lon.T, cmap=plot_cmap, vmin=0)
101-
bk_plot.ax_th.pcolormesh( tedges, zedges, alt_time.T, cmap=plot_cmap, vmin=0)
128+
bk_plot.ax_lon.pcolormesh( xedges, zedges, alt_lon.T, cmap=plot_cmap, vmin=plot_vmin, **kwargs)
129+
bk_plot.ax_lat.pcolormesh( zedges, yedges, alt_lat.T, cmap=plot_cmap, vmin=plot_vmin, **kwargs)
130+
bk_plot.ax_plan.pcolormesh(xedges, yedges, lat_lon.T, cmap=plot_cmap, vmin=plot_vmin, **kwargs)
131+
bk_plot.ax_th.pcolormesh( tedges, zedges, alt_time.T, cmap=plot_cmap, vmin=plot_vmin, **kwargs)
102132
bk_plot.ax_hist.hist(alt_data, orientation='horizontal',
103133
density=True, bins=80, range=(0, 20))
104134
plt.text(0.25, 0.10, str(len(alt_data)) + ' src',

0 commit comments

Comments
 (0)