Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed geoseries.dashboard gridspec and docstring #440

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 58 additions & 33 deletions pyleoclim/core/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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):
'''

Expand All @@ -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.

Expand All @@ -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 <https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.gridspec.GridSpec.html#matplotlib.gridspec.GridSpec>_. The default is None.
Expand Down Expand Up @@ -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
--------
Expand All @@ -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
Expand Down Expand Up @@ -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']})

Expand All @@ -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]
Expand Down Expand Up @@ -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']})

Expand Down Expand Up @@ -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)
Expand Down