Skip to content

Commit

Permalink
Fix problems with graphics (#604)
Browse files Browse the repository at this point in the history
* Fix problems with graphics

* update archiveType logic in ensgeoseries

* remove errant print statement

* include archiveType logic in dashboard function

---------

Co-authored-by: khider <[email protected]>
Co-authored-by: Alexander James <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2024
1 parent b4b1d6f commit 5ad1375
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
27 changes: 25 additions & 2 deletions pyleoclim/core/ensemblegeoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import warnings

from collections import Counter

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
Expand Down Expand Up @@ -86,6 +88,19 @@ def __init__(self, series_list,label=None,lat=None,lon=None,elevation=None,archi

super().__init__(series_list,label)

# Assign archiveType if it isn't passed and it is present in all series in series_list
if archiveType is None:
if not all([isinstance(ts, GeoSeries) for ts in series_list]):
pass
else:
archiveList = [str(ts.archiveType) for ts in series_list]
#Check that they're all the same
if all([a == archiveList[0] for a in archiveList]):
archiveType = archiveList[0]
#If they aren't, pick the most common one
else:
archiveType = Counter(archiveList).most_common(1)[0][0]

if lat is None:
# check that all components are GeoSeries
if not all([isinstance(ts, GeoSeries) for ts in series_list]):
Expand Down Expand Up @@ -619,8 +634,16 @@ def dashboard(self, figsize=[11, 8], gs=None, plt_kwargs=None, histplt_kwargs=No
if archiveType not in lipdutils.PLOT_DEFAULT.keys():
archiveType = 'Other'
else:
archiveType = 'Other'

if not all([isinstance(ts, GeoSeries) for ts in self.series_list]):
archiveType = 'Other'
else:
archiveList = [str(ts.archiveType) for ts in self.series_list]
#Check that they're all the same
if all([a == archiveList[0] for a in archiveList]):
archiveType = archiveList[0]
#If they aren't, pick the most common one
else:
archiveType = Counter(archiveList).most_common(1)[0][0]
# if 'marker' not in plt_kwargs.keys():
# plt_kwargs.update({'marker': lipdutils.PLOT_DEFAULT[archiveType][1]})
if 'curve_clr' not in plt_kwargs.keys():
Expand Down
13 changes: 9 additions & 4 deletions pyleoclim/core/ensembleseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..core.multipleseries import MultipleSeries

import warnings
warnings.filterwarnings("ignore")

import seaborn as sns
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -666,7 +667,7 @@ def correlation(self, target=None, timespan=None, alpha=0.05, method = 'ttest',
return corr_ens

def plot_traces(self, figsize=[10, 4], xlabel=None, ylabel=None, title=None, num_traces=10, seed=None,
xlim=None, ylim=None, linestyle='-', savefig_settings=None, ax=None, plot_legend=True,
xlim=None, ylim=None, linestyle='-', savefig_settings=None, ax=None, legend=True,
color=sns.xkcd_rgb['pale red'], lw=0.5, alpha=0.3, lgd_kwargs=None):
'''Plot EnsembleSeries as a subset of traces.
Expand Down Expand Up @@ -804,19 +805,23 @@ def plot_traces(self, figsize=[10, 4], xlabel=None, ylabel=None, title=None, num

for idx in random_draw_idx:
self.series_list[idx].plot(xlabel=xlabel, ylabel=ylabel, zorder=99, linewidth=lw,
xlim=xlim, ylim=ylim, ax=ax, color=color, alpha=alpha,linestyle='-')
ax.plot(np.nan, np.nan, color=color, label=f'example members (n={num_traces})',linestyle='-')
xlim=xlim, ylim=ylim, ax=ax, color=color, alpha=alpha,linestyle='-', label='_ignore')
l1, = ax.plot(np.nan, np.nan, color=color, label=f'example members (n={num_traces})',linestyle='-')

if title is not None:
ax.set_title(title)
else:
if self.label is not None:
ax.set_title(self.label)

if plot_legend:
if legend==True:
lgd_args = {'frameon': False}
lgd_args.update(lgd_kwargs)
ax.legend(**lgd_args)
elif legend==False:
ax.legend().remove()
else:
raise ValueError('legend should be set to either True or False')

if 'fig' in locals():
if 'path' in savefig_settings:
Expand Down

0 comments on commit 5ad1375

Please sign in to comment.