From 09094664825147a73da41e2dcff85c19d5c78157 Mon Sep 17 00:00:00 2001 From: jlanders Date: Mon, 12 Jun 2023 14:48:10 -0700 Subject: [PATCH] fixed geoseries.dashboard gridspec and docstring --- pyleoclim/core/geoseries.py | 91 +++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/pyleoclim/core/geoseries.py b/pyleoclim/core/geoseries.py index 6d7012b4..9e6d2b05 100644 --- a/pyleoclim/core/geoseries.py +++ b/pyleoclim/core/geoseries.py @@ -305,13 +305,13 @@ def map(self, projection='Orthographic', proj_default=True, import pyleoclim as pyleo ts = pyleo.utils.datasets.load_dataset('EDC-dD') - fig, ax = ts.map(lgd_kwargs={'bbox_to_anchor':(1, 1)}) # by default, the legend conflicts with the map, but it's easy to push it outside with this keyword argument' + fig, ax = ts.map() # by default, the legend conflicts with the map, but it's easy to push it outside with this keyword argument' ''' if markersize != None: scatter_kwargs['markersize'] = markersize - fig, ax = mapping.scatter_map(self, hue=hue, size=size, marker=marker, projection=projection, + fig, ax_d = mapping.scatter_map(self, hue=hue, size=size, marker=marker, projection=projection, proj_default=proj_default, background=background, borders=borders, rivers=rivers, lakes=lakes, ocean=ocean, @@ -320,7 +320,7 @@ def map(self, projection='Orthographic', proj_default=True, lgd_kwargs=lgd_kwargs, legend=legend, colorbar=colorbar, cmap=cmap, edgecolor=edgecolor, fig=fig, gs_slot=gridspec_slot) - return fig, ax + return fig, ax_d # scatter_kwargs = {} if scatter_kwargs is None else scatter_kwargs.copy() # # get the information from the timeseries @@ -406,8 +406,10 @@ def map(self, projection='Orthographic', proj_default=True, # # return res - def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spectral_kwargs=None, - spectralsignif_kwargs=None, spectralfig_kwargs=None, map_kwargs=None,gridspec_kwargs=None, + def dashboard(self, figsize=[11, 8], gs=None, plt_kwargs=None, histplt_kwargs=None, spectral_kwargs=None, + spectralsignif_kwargs=None, spectralfig_kwargs=None, map_kwargs=None, + hue='archiveType', marker='archiveType', size=None, scatter_kwargs=None, + gridspec_kwargs=None, savefig_settings=None): ''' @@ -417,6 +419,15 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect figsize : list or tuple, optional Figure size. The default is [11,8]. + gs : matplotlib.gridspec object, optional + Requires at least two rows and 4 columns. + - top row, left: timeseries + - top row, right: histogram + - bottom left: map + - bottom right: PSD + See [matplotlib.gridspec.GridSpec](https://matplotlib.org/stable/tutorials/intermediate/gridspec.html) for details. + + plt_kwargs : dict, optional Optional arguments for the timeseries plot. See Series.plot() or EnsembleSeries.plot_envelope(). The default is None. @@ -433,11 +444,31 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect Optional arguments for the power spectrum figure. See PSD.plot() or MultiplePSD.plot_envelope(). The default is None. map_kwargs : dict, optional - Optional arguments for the map and point plotted on map. - - scatter_kwargs: dict of values for configuring how data are plotted on a map - - gridspec_kwargs: dict of values for how the map gridspec is configured + Optional arguments for map configuration + - projection: str; Optional value for map projection. Default 'auto'. + - proj_default: bool + - lakes, land, ocean, rivers, borders, coastline, background: bool or dict; + - lgd_kwargs: dict; Optional values for how the map legend is configured + - gridspec_kwargs: dict; Optional values for adjusting the arrangement of the colorbar, map and legend in the map subplot + - legend: bool; Whether to draw a legend on the figure. Default is True + - colorbar: bool; Whether to draw a colorbar on the figure if the data associated with hue are numeric. Default is True The default is None. + hue : str, optional + Variable associated with color coding for points plotted on map. May correspond to a continuous or categorical variable. + The default is 'archiveType'. + + size : str, optional + Variable associated with size. Must correspond to a continuous numeric variable. + The default is None. + + marker : string, optional + Grouping variable that will produce points with different markers. Can have a numeric dtype but will always be treated as categorical. + The default is 'archiveType'. + + scatter_kwargs : dict, optional + Optional arguments configuring how data are plotted on a map. See description of scatter_kwargs in pyleoclim.utils.mapping.scatter_map + gridspec_kwargs : dict, optional Optional dictionary for configuring dashboard layout using gridspec For information about Gridspec configuration, refer to `Matplotlib documentation _. The default is None. @@ -481,7 +512,7 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect pyleoclim.core.geoseries.GeoSeries.map : map location of dataset - pyleoclim.utils.mapping.map : Underlying mapping function for Pyleoclim + pyleoclim.utils.mapping.scatter_map : Underlying mapping function for Pyleoclim Examples -------- @@ -498,16 +529,12 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect # start plotting fig = plt.figure(figsize=figsize) - gridspec_kwargs = {} if type(gridspec_kwargs) != dict else gridspec_kwargs - gridspec_defaults = dict(wspace=0, width_ratios=[1,1,1,.25,1,1,1], - height_ratios=[1,.1,1], left=0, right=1.1) - - gridspec_defaults.update(gridspec_kwargs) - gs = gridspec.GridSpec(len(gridspec_defaults['height_ratios']), len(gridspec_defaults['width_ratios']), **gridspec_defaults) - - # gs = gridspec.GridSpec(2, 6, wspace=0) - # gs.update(left=0, right=1.1) - + if gs == None: + gridspec_kwargs = {} if type(gridspec_kwargs) != dict else gridspec_kwargs + gridspec_defaults = dict(wspace=0, width_ratios=[3, .25, 2, 1], + height_ratios=[1, .1, 1], left=0, right=1.1) + gridspec_defaults.update(gridspec_kwargs) + gs = gridspec.GridSpec(len(gridspec_defaults['height_ratios']), len(gridspec_defaults['width_ratios']), **gridspec_defaults) ax = {} # Plot the timeseries @@ -557,14 +584,9 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect coastline = map_kwargs.pop('coastline', True) background = map_kwargs.pop('background', True) - gridspec_kwargs = map_kwargs.pop('gridspec_kwargs', {}) - scatter_kwargs = map_kwargs.pop('scatter_kwargs', {}) + map_gridspec_kwargs = map_kwargs.pop('gridspec_kwargs', {}) lgd_kwargs = map_kwargs.pop('lgd_kwargs', {}) - marker = scatter_kwargs.pop('marker', 'archiveType') - hue = scatter_kwargs.pop('hue', 'archiveType') - size = scatter_kwargs.pop('size', None) - if 'edgecolor' in map_kwargs.keys(): scatter_kwargs.update({'edgecolor': map_kwargs['edgecolor']}) @@ -573,13 +595,13 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect colorbar = map_kwargs.pop('colorbar', False) if legend == False: - gridspec_kwargs['width_ratios'] = [.5,16, 1] + map_gridspec_kwargs['width_ratios'] = [.5,16, 1] _, ax['map'] =mapping.scatter_map(self, hue=hue, size=size, marker=marker, projection=projection, proj_default=proj_default, background=background, borders=borders, coastline=coastline, rivers=rivers, lakes=lakes, ocean=ocean, land=land, - figsize=None, scatter_kwargs=scatter_kwargs,gridspec_kwargs = gridspec_kwargs, + figsize=None, scatter_kwargs=scatter_kwargs,gridspec_kwargs = map_gridspec_kwargs, lgd_kwargs=lgd_kwargs, legend=legend, cmap=cmap, colorbar=colorbar, - fig=fig, gs_slot=gs[-1, 0:-4]) + fig=fig, gs_slot=gs[-1, 0:1]) # make the map - brute force since projection is not being returned properly # lat = [self.lat] @@ -675,7 +697,7 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect else: spectral_kwargs.update({'freq_method': 'lomb_scargle'}) - ax['spec'] = fig.add_subplot(gs[-1, -3:]) + ax['spec'] = fig.add_subplot(gs[-1, -2:]) spectralfig_kwargs = {} if spectralfig_kwargs is None else spectralfig_kwargs.copy() spectralfig_kwargs.update({'ax': ax['spec']}) @@ -733,10 +755,13 @@ def resample(self, rule, keep_log = False, **kwargs): Examples -------- - >>> ts = pyleo.utils.load_dataset('EDC-dD').convert_time_unit('ky BP') - >>> ts5k = ts.resample('1ka').mean() - >>> fig, ax = ts.plot() - >>> ts5k.plot(ax=ax,color='C1') + + .. jupyter-execute:: + + ts = pyleo.utils.load_dataset('EDC-dD').convert_time_unit('ky BP') + ts5k = ts.resample('1ka').mean() + fig, ax = ts.plot() + ts5k.plot(ax=ax,color='C1') """ search = re.search(r'(\d*)([a-zA-Z]+)', rule)