Skip to content

Commit

Permalink
Add gridded data plotting capability (#134)
Browse files Browse the repository at this point in the history
* Add gridded data plotting capability

* pycodestyle

* missed import
  • Loading branch information
kevindougherty-noaa committed Jul 11, 2023
1 parent fb78288 commit cc94d33
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/emcpy/plots/create_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def create_figure(self):
'histogram': self._histogram,
'density': self._density,
'line_plot': self._lineplot,
'gridded_plot': self._gridded,
'vertical_line': self._verticalline,
'horizontal_line': self._horizontalline,
'horizontal_span': self._horizontalspan,
Expand Down Expand Up @@ -538,6 +539,20 @@ def _scatter(self, plotobj, ax):
plotobj.linear_regression['color'] = inputs['color']
ax.plot(plotobj.x, y_pred, label=label, **plotobj.linear_regression)

def _gridded(self, plotobj, ax):
"""
Uses Gridded object to plot on axis.
"""
skipvars = ['plottype', 'plot_ax', 'x', 'y', 'z',
'colorbar']
inputs = self._get_inputs_dict(skipvars, plotobj)

cs = ax.pcolormesh(plotobj.x, plotobj.y,
plotobj.z, **inputs)

if plotobj.colorbar:
self.cs = cs

def _skewt(self, plotobj, ax):
"""
Creates a skewt-logp profile plot on axis.
Expand Down
27 changes: 27 additions & 0 deletions src/emcpy/plots/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,33 @@ def __init__(self, x, y):
self.label = None


class GriddedPlot:

def __init__(self, x, y, z):
"""
Constructor for GriddedPlot.
Args:
x : (array type)
y : (array type)
z : (array type)
"""
super().__init__()
self.plottype = 'gridded_plot'

self.x = x
self.y = y
self.z = z

self.cmap = 'viridis'
self.norm = None
self.vmin = None
self.vmax = None
self.edgecolors = None
self.shading = 'auto'
self.alpha = None
self.colorbar = True


class VerticalLine:

def __init__(self, x):
Expand Down
35 changes: 34 additions & 1 deletion src/tests/test_plots.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import numpy as np
from scipy.ndimage.filters import gaussian_filter
import matplotlib.pyplot as plt

from emcpy.plots.plots import LinePlot, VerticalLine,\
Histogram, Density, Scatter, HorizontalLine, BarPlot, \
HorizontalBar, HorizontalSpan, SkewT
GriddedPlot, HorizontalBar, HorizontalSpan, SkewT
from emcpy.plots.create_plots import CreatePlot, CreateFigure


Expand Down Expand Up @@ -248,6 +249,26 @@ def test_bar_plot():
fig.save_figure('test_bar_plot.png')


def test_gridded_plot():
# Create gridded plot

x, y, z = _getGriddedData()

gp = GriddedPlot(x, y, z)
gp.cmap = 'plasma'

plot1 = CreatePlot()
plot1.plot_layers = [gp]
plot1.add_xlabel(xlabel='X Axis Label')
plot1.add_ylabel(ylabel='Y Axis Label')
plot1.add_title('Test Gridded Plot')

fig = CreateFigure()
fig.plot_list = [plot1]
fig.create_figure()
fig.save_figure('test_gridded_plot.png')


def test_horizontal_bar_plot():
# Create horizontal bar plot

Expand Down Expand Up @@ -522,6 +543,17 @@ def _getBarData():
return x_pos, heights, variance


def _getGriddedData():
# generate test data for gridded data

x = np.linspace(0, 1, 51)
y = np.linspace(0, 1, 51)
r = np.random.RandomState(25)
z = gaussian_filter(r.random_sample([50, 50]), sigma=5, mode='wrap')

return x, y, z


def _getSkewTData():
# use data for skew-t log-p plot
from io import StringIO
Expand Down Expand Up @@ -616,6 +648,7 @@ def main():
test_histogram_plot()
test_scatter_plot()
test_bar_plot()
test_gridded_plot()
test_horizontal_bar_plot()
test_multi_subplot()
test_HorizontalSpan()
Expand Down

0 comments on commit cc94d33

Please sign in to comment.