Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b0b470

Browse files
committed
Stash progress
1 parent 5bf295a commit 0b0b470

File tree

3 files changed

+2186
-2171
lines changed

3 files changed

+2186
-2171
lines changed

‎proplot/axes/base.py

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def _plot_redirect(self, name, *args, **kwargs):
696696
if getattr(self, 'name', '') == 'basemap':
697697
return getattr(self.projection, name)(*args, ax=self, **kwargs)
698698
else:
699-
return getattr(maxes.Axes, name)(self, *args, **kwargs)
699+
return getattr(super(), name)(self, *args, **kwargs)
700700

701701
def _range_gridspec(self, x):
702702
"""
@@ -1244,7 +1244,7 @@ def areax(self, *args, **kwargs):
12441244
# bar = _bar_wrapper(_standardize_1d(_indicate_error(_cycle_changer(
12451245
@plot._concatenate_docstrings
12461246
@docstring.add_snippets
1247-
@plot._add_autoformat
1247+
@plot._with_autoformat
12481248
def bar(
12491249
self, x=None, height=None, width=0.8, bottom=None, *,
12501250
vert=None, orientation='vertical', stacked=False,
@@ -1268,6 +1268,23 @@ def bar(
12681268
kwargs, kwargs_legend_colorbar = plot._parse_cycle(**kwargs)
12691269
kwargs, kwargs_error = plot._parse_error(**kwargs)
12701270

1271+
# Get step size for bar plots
1272+
# WARNING: This will fail for non-numeric non-datetime64 singleton
1273+
# datatypes but this is good enough for vast majority of cases.
1274+
if not stacked and not getattr(self, '_absolute_bar_width', False):
1275+
x_test = np.atleast_1d(_to_ndarray(x))
1276+
if len(x_test) >= 2:
1277+
x_step = x_test[1:] - x_test[:-1]
1278+
x_step = np.concatenate((x_step, x_step[-1:]))
1279+
elif x_test.dtype == np.datetime64:
1280+
x_step = np.timedelta64(1, 'D')
1281+
else:
1282+
x_step = np.array(0.5)
1283+
if np.issubdtype(x_test.dtype, np.datetime64):
1284+
# Avoid integer timedelta truncation
1285+
x_step = x_step.astype('timedelta64[ns]')
1286+
width = width * x_step / ncols
1287+
12711288
# Parse args
12721289
# TODO: Stacked feature is implemented in `cycle_changer`, but makes more
12731290
# sense do document here; figure out way to move it here?
@@ -1369,7 +1386,7 @@ def boxes(self, *args, **kwargs):
13691386
# boxplot = _boxplot_wrapper(_standardize_1d(_cycle_changer(
13701387
@plot._concatenate_docstrings
13711388
@docstring.add_snippets
1372-
@plot._add_autoformat
1389+
@plot._with_autoformat
13731390
def boxplot(
13741391
self, *args,
13751392
color='k', fill=True, fillcolor=None, fillalpha=0.7,
@@ -1716,10 +1733,19 @@ def contour(self, *args, **kwargs):
17161733
%(plot.auto_colorbar)s
17171734
%(plot.cmap_args)s
17181735
"""
1736+
# Parse arguments
17191737
args = plot._parse_2d(*args)
17201738
kwargs, kwargs_colorbar = plot._parse_cmap(**kwargs)
1739+
kwargs, kwargs_label = plot._parse_labels(**kwargs)
1740+
1741+
# Call main function
17211742
mappable = self._plot_redirect('contour', *args, **kwargs)
1743+
1744+
# Post-processing
1745+
plot._auto_contour_labels(mappable, **kwargs_label)
17221746
plot._auto_colorbar(mappable, **kwargs_colorbar)
1747+
plot._edgefix_contour(mappable)
1748+
17231749
return mappable
17241750

17251751
@plot._concatenate_docstrings
@@ -1840,7 +1866,7 @@ def _fill_between_apply(
18401866

18411867
@plot._concatenate_docstrings
18421868
@docstring.add_snippets
1843-
@plot._add_autoformat
1869+
@plot._with_autoformat
18441870
def fill_between(self, *args, **kwargs):
18451871
"""
18461872
%(axes.fill_between)s
@@ -1849,7 +1875,7 @@ def fill_between(self, *args, **kwargs):
18491875

18501876
@plot._concatenate_docstrings
18511877
@docstring.add_snippets
1852-
@plot._add_autoformat
1878+
@plot._with_autoformat
18531879
def fill_betweenx(self, *args, **kwargs):
18541880
"""
18551881
%(axes.fill_betweenx)s
@@ -1934,7 +1960,7 @@ def hexbin(self, *args, **kwargs):
19341960
# hist = _hist_wrapper(_standardize_1d(_cycle_changer(
19351961
@plot._concatenate_docstrings
19361962
@docstring.add_snippets
1937-
@plot._add_autoformat
1963+
@plot._with_autoformat
19381964
def hist(self, x, bins=None, **kwargs):
19391965
"""
19401966
Add histogram(s).
@@ -2395,7 +2421,7 @@ def parametric(
23952421
)
23962422
else:
23972423
raise ValueError('Missing required keyword argument "values".')
2398-
cmap, norm, kwargs = plot._parse_cmap_norm(**kwargs)
2424+
kwargs, kwargs_colorbar = plot._parse_cmap(**kwargs)
23992425

24002426
# Verify shapes
24012427
x, y, values = np.atleast_1d(x), np.atleast_1d(y), np.atleast_1d(values)
@@ -2446,27 +2472,26 @@ def parametric(
24462472
coords.append(np.concatenate((pleft, pright), axis=0))
24472473
coords = np.array(coords)
24482474

2449-
# Create LineCollection and update with values
2475+
# Add LineCollection and update with values
24502476
# NOTE: Default capstyle is butt but this may look weird with vector graphics
2451-
obj = mcollections.LineCollection(
2452-
coords, cmap=cmap, norm=norm,
2453-
linestyles='-', capstyle='butt', joinstyle='miter',
2454-
)
2455-
values = np.asarray(values)
2456-
obj.set_array(values)
2457-
obj.update({
2458-
key: value for key, value in kwargs.items()
2459-
if key not in ('color',)
2460-
})
2477+
# NOTE: Calling set_array is what triggers LineCollection to determine
2478+
# colors using ScalarMappable and normalizer.
2479+
kwargs.setdefault('capstyle', 'butt')
2480+
kwargs.setdefault('joinstyle', 'miter')
2481+
kwargs.setdefault('linestyles', '-')
2482+
mappable = mcollections.LineCollection(coords, **kwargs)
2483+
mappable.set_array(values)
2484+
self.add_collection(mappable)
2485+
self.autoscale_view(scalex=scalex, scaley=scaley)
24612486

24622487
# Add collection with some custom attributes
24632488
# NOTE: Modern API uses self._request_autoscale_view but this is
24642489
# backwards compatible to earliest matplotlib versions.
2465-
self.add_collection(obj)
2466-
self.autoscale_view(scalex=scalex, scaley=scaley)
2467-
obj.values = values
2468-
obj.levels = levels # needed for other functions
2469-
return obj
2490+
mappable.values = values
2491+
mappable.levels = levels # needed for other functions
2492+
plot._auto_colorbar(mappable, **kwargs_colorbar)
2493+
2494+
return mappable
24702495

24712496
@plot._concatenate_docstrings
24722497
@docstring.add_snippets
@@ -2542,7 +2567,7 @@ def pie(self, *args, **kwargs):
25422567
# plot = _plot_wrapper(_standardize_1d(_indicate_error(_cycle_changer(
25432568
@plot._concatenate_docstrings
25442569
@docstring.add_snippets
2545-
@plot._add_autoformat
2570+
@plot._with_autoformat
25462571
def plot(self, *args, cmap=None, values=None, **kwargs):
25472572
"""
25482573
Parameters
@@ -2622,7 +2647,7 @@ def quiver(self, *args, **kwargs):
26222647
# scatter = _scatter_wrapper(_standardize_1d(_indicate_error(_cycle_changer(
26232648
@plot._concatenate_docstrings
26242649
@docstring.add_snippets
2625-
@plot._add_autoformat
2650+
@plot._with_autoformat
26262651
def scatter(
26272652
self, *args,
26282653
s=None, size=None, markersize=None,

‎proplot/axes/geo.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import copy
66

7+
import matplotlib.axes as maxes
78
import matplotlib.axis as maxis
89
import matplotlib.path as mpath
910
import matplotlib.text as mtext
@@ -14,9 +15,15 @@
1415
from .. import crs as pcrs
1516
from ..config import rc
1617
from ..internals import ic # noqa: F401
17-
from ..internals import _not_none, _version, _version_cartopy, docstring, warnings
18+
from ..internals import (
19+
_not_none,
20+
_state_context,
21+
_version,
22+
_version_cartopy,
23+
docstring,
24+
warnings,
25+
)
1826
from . import base
19-
from .plot import _basemap_norecurse
2027

2128
try:
2229
import cartopy.crs as ccrs
@@ -1317,6 +1324,16 @@ def _iter_gridlines(dict_):
13171324
for obj in pj:
13181325
yield obj
13191326

1327+
def _plot_norecurse(self, name, *args, **kwargs):
1328+
"""
1329+
Call the plotting method and avoid recursion.
1330+
"""
1331+
if self._called_from_basemap:
1332+
return getattr(maxes.Axes, name)(self, *args, **kwargs)
1333+
else:
1334+
with _state_context(self, _called_from_basemap=True):
1335+
return getattr(super(), name)(self, *args, **kwargs)
1336+
13201337
def _update_extent(self, lonlim=None, latlim=None, boundinglat=None):
13211338
"""
13221339
No-op. Map bounds cannot be changed in basemap.
@@ -1512,57 +1529,48 @@ def projection(self, map_projection):
15121529
self._map_projection = map_projection
15131530

15141531
# Undocumented plotting overrides
1515-
@_basemap_norecurse
1532+
# NOTE: Simpler to document latlon=True and transform=PlateCarree()
1533+
# default behavior in 'Note' boxes on all base plotting methods.
15161534
def barbs(self, *args, latlon=True, **kwargs):
15171535
# Use latlon=True by default
1518-
return super().barbs(*args, latlon=latlon, **kwargs)
1536+
return self._plot_norecurse('barbs', *args, latlon=latlon, **kwargs)
15191537

1520-
@_basemap_norecurse
15211538
def contour(self, *args, latlon=True, **kwargs):
15221539
# Use latlon=True by default
1523-
return super().contour(*args, latlon=latlon, **kwargs)
1540+
return self._plot_norecurse('contour', *args, latlon=latlon, **kwargs)
15241541

1525-
@_basemap_norecurse
15261542
def contourf(self, *args, latlon=True, **kwargs):
15271543
# Use latlon=True by default
1528-
return super().contourf(*args, latlon=latlon, **kwargs)
1544+
return self._plot_norecurse('contourf', *args, latlon=latlon, **kwargs)
15291545

1530-
@_basemap_norecurse
15311546
def hexbin(self, *args, latlon=True, **kwargs):
15321547
# Use latlon=True by default
1533-
return super().hexbin(*args, latlon=latlon, **kwargs)
1548+
return self._plot_norecurse('hexbin', *args, latlon=latlon, **kwargs)
15341549

1535-
@_basemap_norecurse
15361550
def imshow(self, *args, latlon=True, **kwargs):
15371551
# Use latlon=True by default
1538-
return super().imshow(*args, latlon=latlon, **kwargs)
1552+
return self._plot_norecurse('imshow', *args, latlon=latlon, **kwargs)
15391553

1540-
@_basemap_norecurse
15411554
def pcolor(self, *args, latlon=True, **kwargs):
15421555
# Use latlon=True by default
1543-
return super().pcolor(*args, latlon=latlon, **kwargs)
1556+
return self._plot_norecurse('pcolor', *args, latlon=latlon, **kwargs)
15441557

1545-
@_basemap_norecurse
15461558
def pcolormesh(self, *args, latlon=True, **kwargs):
15471559
# Use latlon=True by default
1548-
return super().pcolormesh(*args, latlon=latlon, **kwargs)
1560+
return self._plot_norecurse('pcolormesh', *args, latlon=latlon, **kwargs)
15491561

1550-
@_basemap_norecurse
15511562
def plot(self, *args, latlon=True, **kwargs):
15521563
# Use latlon=True by default
1553-
return super().plot(*args, latlon=latlon, **kwargs)
1564+
return self._plot_norecurse('plot', *args, latlon=latlon, **kwargs)
15541565

1555-
@_basemap_norecurse
15561566
def quiver(self, *args, latlon=True, **kwargs):
15571567
# Use latlon=True by default
1558-
return super().quiver(*args, latlon=latlon, **kwargs)
1568+
return self._plot_norecurse('quiver', *args, latlon=latlon, **kwargs)
15591569

1560-
@_basemap_norecurse
15611570
def scatter(self, *args, latlon=True, **kwargs):
15621571
# Use latlon=True by default
1563-
return super().scatter(*args, latlon=latlon, **kwargs)
1572+
return self._plot_norecurse('scatter', *args, latlon=latlon, **kwargs)
15641573

1565-
@_basemap_norecurse
15661574
def streamplot(self, *args, latlon=True, **kwargs):
15671575
# Use latlon=True by default
1568-
return super().streamplot(*args, latlon=latlon, **kwargs)
1576+
return self._plot_norecurse('streamplot', *args, latlon=latlon, **kwargs)

0 commit comments

Comments
 (0)