Skip to content
Snippets Groups Projects
Unverified Commit 6ac0019f authored by David Hoese's avatar David Hoese
Browse files

Add temperature and dewpoint specific plot maker

parent 02227946
No related branches found
No related tags found
No related merge requests found
......@@ -66,7 +66,7 @@ class PlotMaker(object):
new_ticks = np.arange(ymin, (ymin + delta * num_plots), delta)
return new_ticks
def get_ylabel(self, is_subplot=False):
def _get_ylabel(self, is_subplot=False):
y_label = TITLES.get(self.name, self.name.replace('_', ' ').title())
if is_subplot:
return None
......@@ -74,16 +74,25 @@ class PlotMaker(object):
return "{} ({})".format(y_label, self.units)
return y_label
def create_plot(self, frame, fig, start_time=None, end_time=None,
is_subplot=None, shared_x=None, title=None):
"""
def _set_ylabel(self, ax, is_subplot=False):
y_label = self._get_ylabel(is_subplot)
if y_label and not is_subplot:
ax.set_ylabel(y_label)
:param frame:
:param fig:
:param is_subplot: None or (num plots, num columns, num_rows)
:param shared_x:
:return:
"""
def _call_plot(self, frame, ax):
lines = ax.plot(frame.index, frame, 'k')
return lines
def _set_ylim(self, frame, ax):
ymin = np.floor(frame.min().min())
ymax = np.ceil(frame.max().max())
if ymin == ymax:
ax.set_ylim(ymin, ymax + 0.1)
else:
ax.set_ylim(ymin, ymax)
return ymin, ymax
def _set_title(self, frame, fig, ax, start_time=None, end_time=None, title=None, is_subplot=None):
if start_time is None:
start_time = frame.index[0].to_pydatetime()
if end_time is None:
......@@ -92,37 +101,62 @@ class PlotMaker(object):
title = self.get_title(frame, is_subplot, start_time, end_time)
if is_subplot:
ax = fig.add_subplot(*is_subplot, sharex=shared_x)
ax.set_title(title, x=0.5, y=get_subtitle_location(is_subplot[0]), fontsize=8)
else:
ax = fig.add_subplot(111, sharex=shared_x)
fig.suptitle(title, fontsize=13)
y_label = self.get_ylabel(is_subplot)
if y_label:
ax.set_ylabel(y_label)
plt.sca(ax)
# get the min for each column then combine them assuming we can
specific_frame = frame[[x for x in frame.columns if x in self.deps]]
ymin = np.floor(specific_frame.min().min())
ymax = np.ceil(specific_frame.max().max())
ax.plot(specific_frame.index, specific_frame, 'k')
if ymin == ymax:
ax.set_ylim(ymin, ymax + 0.1)
def _get_axes(self, fig, is_subplot, shared_x=None):
if is_subplot:
ax = fig.add_subplot(*is_subplot, sharex=shared_x)
else:
ax.set_ylim(ymin, ymax)
ax = fig.add_subplot(111, sharex=shared_x)
plt.sca(ax)
return ax
def _set_xlabel(self, ax, is_subplot):
if not is_subplot:
ax.set_xlabel('Time (UTC)')
def _set_yticks(self, ax, ymin, ymax, is_subplot):
if is_subplot:
new_ticks = self.get_yticks(ymin, ymax, is_subplot[0])
ax.get_yaxis().get_major_ticks()[-1].set_visible(False)
ax.set_yticks(new_ticks)
else:
ax.set_xlabel('Time (UTC)')
def create_plot(self, frame, fig, start_time=None, end_time=None,
is_subplot=None, shared_x=None, title=None):
"""
:param frame:
:param fig:
:param is_subplot: None or (num plots, num columns, num_rows)
:param shared_x:
:return:
"""
ax = self._get_axes(fig, is_subplot, shared_x)
self._set_title(frame, fig, ax,
start_time=start_time, end_time=end_time,
title=title, is_subplot=is_subplot)
# get the min for each column then combine them assuming we can
specific_frame = frame[[x for x in frame.columns if x in self.deps]]
lines = self._call_plot(specific_frame, ax)
ymin, ymax = self._set_ylim(specific_frame, ax)
self._set_yticks(ax, ymin, ymax, is_subplot)
self._set_xlabel(ax, is_subplot)
self._set_ylabel(ax, is_subplot)
return ax
class TDPlotMaker(PlotMaker):
def _call_plot(self, frame, ax):
air_temp = self.deps[0]
dewpoint = self.deps[1]
ax.plot(frame.index, frame[air_temp], 'r', frame.index, frame[dewpoint], 'g')
class MeteorogramPlotMaker(PlotMaker):
def __init__(self, name, dependencies, plot_deps=None, title=None):
self.plot_deps = plot_deps
......@@ -153,9 +187,11 @@ class MeteorogramPlotMaker(PlotMaker):
if idx == 0:
shared_x = ax
if idx != num_plots - 1:
print("Disabling")
# Disable the x-axis ticks so we don't interfere with other subplots
ax.get_xaxis().get_major_ticks()[-1].set_visible(False)
ax.get_xaxis().get_major_ticks()[0].set_visible(False)
ax.set_xticklabels([''] * len(ax.get_xticklabels()))
# ax.get_xaxis().get_major_ticks()[-1].set_visible(False)
# ax.get_xaxis().get_major_ticks()[0].set_visible(False)
ax.set_xlabel('Time (UTC)')
fig.subplots_adjust(hspace=0, bottom=0.125)
......@@ -167,7 +203,7 @@ PLOT_TYPES = {
'meteorogram': MeteorogramPlotMaker('meteorogram',
('air_temp', 'dewpoint', 'rh', 'wind_speed', 'wind_dir', 'accum_precip'),
('td', 'rh', 'wind_speed', 'wind_dir', 'accum_precip')),
'td': PlotMaker('td', ('air_temp', 'dewpoint'), units="°C"), # air_temp and dewpoint in one plot
'td': TDPlotMaker('td', ('air_temp', 'dewpoint'), units="°C"), # air_temp and dewpoint in one plot
'wind_dir': PlotMaker('wind_dir', ('wind_dir',), units='°'), # special tick labels
'rh': PlotMaker('rh', ('rh',), units='%'),
'air_temp': PlotMaker('air_temp', ('air_temp',), units='°C'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment