Skip to content

Commit 5a2221f

Browse files
committed
Partial commit
1 parent 3f16210 commit 5a2221f

File tree

2 files changed

+166
-163
lines changed

2 files changed

+166
-163
lines changed

proplot/axes/base.py

Lines changed: 166 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
_barh_wrapper,
2525
_boxplot_wrapper,
2626
_cmap_changer,
27+
_concatenate_docstrings,
2728
_cycle_changer,
2829
_fill_between_wrapper,
2930
_fill_betweenx_wrapper,
@@ -32,7 +33,6 @@
3233
_hlines_wrapper,
3334
_indicate_error,
3435
_parametric_wrapper,
35-
_plot_wrapper,
3636
_scatter_wrapper,
3737
_standardize_1d,
3838
_standardize_2d,
@@ -1657,14 +1657,6 @@ def parametric(
16571657
values : list of float
16581658
The parametric values used to map points on the line to colors
16591659
in the colormap. This can also be passed as a third positional argument.
1660-
cmap : colormap spec, optional
1661-
The colormap specifier, passed to `~proplot.constructor.Colormap`.
1662-
cmap_kw : dict, optional
1663-
Keyword arguments passed to `~proplot.constructor.Colormap`.
1664-
norm : normalizer spec, optional
1665-
The normalizer, passed to `~proplot.constructor.Norm`.
1666-
norm_kw : dict, optional
1667-
Keyword arguments passed to `~proplot.constructor.Norm`.
16681660
interp : int, optional
16691661
If greater than ``0``, we interpolate to additional points
16701662
between the `values` coordinates. The number corresponds to the
@@ -1673,6 +1665,9 @@ def parametric(
16731665
scalex, scaley : bool, optional
16741666
Whether the view limits are adapted to the data limits. The values are
16751667
passed on to `~matplotlib.axes.Axes.autoscale_view`.
1668+
%(standardize_1d_kwargs)s
1669+
%(cycle_changer_kwargs)s
1670+
%(add_errorbars_kwargs)s
16761671
16771672
Other parameters
16781673
----------------
@@ -1687,7 +1682,7 @@ def parametric(
16871682
"""
16881683
# Get x/y coordinates and values for points to the 'left' and 'right'
16891684
# of each joint
1690-
x, y = args # standardized by parametric wrapper
1685+
x, y = _standardize_1d(args)
16911686
interp # avoid U100 unused argument error (arg is handled by wrapper)
16921687
coords = []
16931688
levels = edges(values)
@@ -1731,6 +1726,167 @@ def parametric(
17311726
hs.levels = levels # needed for other functions
17321727
return hs
17331728

1729+
@_concatenate_docstrings
1730+
@docstring.add_snippets
1731+
def plot(self, *args, cmap=None, values=None, **kwargs):
1732+
"""
1733+
Parameters
1734+
----------
1735+
%(standardize_1d_args)s
1736+
cmap, values : optional
1737+
*Deprecated usage*. Passed to `~proplot.axes.Axes.cmapline`.
1738+
%(standardize_1d_kwargs)s
1739+
%(cycle_changer_kwargs)s
1740+
%(add_errorbars_kwargs)s
1741+
1742+
Other parameters
1743+
----------------
1744+
**kwargs
1745+
`~matplotlib.lines.Line2D` properties.
1746+
"""
1747+
if len(args) > 3: # e.g. with fmt string
1748+
raise ValueError(f'Expected 1-3 positional args, got {len(args)}.')
1749+
if cmap is not None:
1750+
warnings._warn_proplot(
1751+
'Drawing "parametric" plots with ax.plot(x, y, values=values, cmap=cmap) '
1752+
'is deprecated and will be removed in a future version. Please use '
1753+
'ax.parametric(x, y, values, cmap=cmap) instead.'
1754+
)
1755+
return self.parametric(*args, cmap=cmap, values=values, **kwargs)
1756+
1757+
# Draw lines
1758+
result = super().plot(*args, values=values, **kwargs)
1759+
1760+
# Add sticky edges? No because there is no way to check whether "dependent variable"
1761+
# is x or y axis like with area/areax and bar/barh. Better to always have margin.
1762+
# for objs in result:
1763+
# if not isinstance(objs, tuple):
1764+
# objs = (objs,)
1765+
# for obj in objs:
1766+
# xdata = obj.get_xdata()
1767+
# obj.sticky_edges.x.extend((np.min(xdata), np.max(xdata)))
1768+
1769+
return result
1770+
1771+
@_concatenate_docstrings
1772+
@docstring.add_snippets
1773+
def scatter_wrapper(
1774+
self, *args,
1775+
s=None, size=None, markersize=None,
1776+
c=None, color=None, markercolor=None, smin=None, smax=None,
1777+
cmap=None, cmap_kw=None, norm=None, norm_kw=None,
1778+
vmin=None, vmax=None, N=None, levels=None, values=None,
1779+
symmetric=False, locator=None, locator_kw=None,
1780+
lw=None, linewidth=None, linewidths=None,
1781+
markeredgewidth=None, markeredgewidths=None,
1782+
edgecolor=None, edgecolors=None,
1783+
markeredgecolor=None, markeredgecolors=None,
1784+
**kwargs
1785+
):
1786+
"""
1787+
Parameters
1788+
----------
1789+
%(standardize_1d_args)s
1790+
s, size, markersize : float or list of float, optional
1791+
The marker size(s). The units are scaled by `smin` and `smax`.
1792+
smin, smax : float, optional
1793+
The minimum and maximum marker size in units points ** 2 used to
1794+
scale the `s` array. If not provided, the marker sizes are equivalent
1795+
to the values in the `s` array.
1796+
c, color, markercolor : color-spec or list thereof, or array, optional
1797+
The marker fill color(s). If this is an array of scalar values, the
1798+
colors will be generated by passing the values through the `norm`
1799+
normalizer and drawing from the `cmap` colormap.
1800+
%(axes.cmap_changer)s
1801+
lw, linewidth, linewidths, markeredgewidth, markeredgewidths : \
1802+
float or list thereof, optional
1803+
The marker edge width.
1804+
edgecolors, markeredgecolor, markeredgecolors : \
1805+
color-spec or list thereof, optional
1806+
The marker edge color.
1807+
%(standardize_1d_kwargs)s
1808+
%(cycle_changer_kwargs)s
1809+
%(add_errorbars_kwargs)s
1810+
1811+
Other parameters
1812+
----------------
1813+
**kwargs
1814+
Passed to `~matplotlib.axes.Axes.scatter`.
1815+
"""
1816+
# Manage input arguments
1817+
# NOTE: Parse 1d must come before this
1818+
nargs = len(args)
1819+
if len(args) > 4:
1820+
raise ValueError(f'Expected 1-4 positional args, got {nargs}.')
1821+
args = list(args)
1822+
if len(args) == 4:
1823+
c = args.pop(1)
1824+
if len(args) == 3:
1825+
s = args.pop(0)
1826+
1827+
# Apply some aliases for keyword arguments
1828+
c = _not_none(c=c, color=color, markercolor=markercolor)
1829+
s = _not_none(s=s, size=size, markersize=markersize)
1830+
lw = _not_none(
1831+
lw=lw, linewidth=linewidth, linewidths=linewidths,
1832+
markeredgewidth=markeredgewidth, markeredgewidths=markeredgewidths,
1833+
)
1834+
ec = _not_none(
1835+
edgecolor=edgecolor, edgecolors=edgecolors,
1836+
markeredgecolor=markeredgecolor, markeredgecolors=markeredgecolors,
1837+
)
1838+
1839+
# Get colormap
1840+
cmap_kw = cmap_kw or {}
1841+
if cmap is not None:
1842+
cmap = constructor.Colormap(cmap, **cmap_kw)
1843+
1844+
# Get normalizer and levels
1845+
# NOTE: If the length of the c array !=
1846+
ticks = None
1847+
carray = np.atleast_1d(c)
1848+
if (
1849+
np.issubdtype(carray.dtype, np.number)
1850+
and not (carray.ndim == 2 and carray.shape[1] in (3, 4))
1851+
):
1852+
carray = carray.ravel()
1853+
norm, cmap, _, ticks = _build_discrete_norm(
1854+
carray, # sample data for getting suitable levels
1855+
N=N, levels=levels, values=values,
1856+
norm=norm, norm_kw=norm_kw,
1857+
locator=locator, locator_kw=locator_kw,
1858+
cmap=cmap, vmin=vmin, vmax=vmax, extend='neither',
1859+
symmetric=symmetric,
1860+
)
1861+
1862+
# Fix 2D arguments but still support scatter(x_vector, y_2d) usage
1863+
# NOTE: Since we are flattening vectors the coordinate metadata is meaningless,
1864+
# so converting to ndarray and stripping metadata is no problem.
1865+
# NOTE: numpy.ravel() preserves masked arrays
1866+
if len(args) == 2 and all(np.asarray(arg).squeeze().ndim > 1 for arg in args):
1867+
args = tuple(np.ravel(arg) for arg in args)
1868+
1869+
# Scale s array
1870+
if np.iterable(s) and (smin is not None or smax is not None):
1871+
smin_true, smax_true = min(s), max(s)
1872+
if smin is None:
1873+
smin = smin_true
1874+
if smax is None:
1875+
smax = smax_true
1876+
s = (
1877+
smin + (smax - smin)
1878+
* (np.array(s) - smin_true) / (smax_true - smin_true)
1879+
)
1880+
obj = super().scatter(
1881+
*args, c=c, s=s, cmap=cmap, norm=norm,
1882+
linewidths=lw, edgecolors=ec, **kwargs
1883+
)
1884+
if ticks is not None:
1885+
obj.ticks = ticks
1886+
return obj
1887+
1888+
1889+
17341890
def violins(self, *args, **kwargs):
17351891
"""
17361892
Alias for `~matplotlib.axes.Axes.violinplot`.

proplot/axes/plot.py

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,159 +1420,6 @@ def parametric_wrapper(self, func, *args, interp=0, **kwargs):
14201420
return func(self, x, y, values=values, **kwargs)
14211421

14221422

1423-
def plot_wrapper(
1424-
self, func, *args, cmap=None, values=None, **kwargs
1425-
):
1426-
"""
1427-
Calls `~proplot.axes.Axes.parametric` in certain cases (but this behavior
1428-
is now deprecated).
1429-
"""
1430-
if len(args) > 3: # e.g. with fmt string
1431-
raise ValueError(f'Expected 1-3 positional args, got {len(args)}.')
1432-
if cmap is not None:
1433-
warnings._warn_proplot(
1434-
'Drawing "parametric" plots with ax.plot(x, y, values=values, cmap=cmap) '
1435-
'is deprecated and will be removed in a future version. Please use '
1436-
'ax.parametric(x, y, values, cmap=cmap) instead.'
1437-
)
1438-
return self.parametric(*args, cmap=cmap, values=values, **kwargs)
1439-
1440-
# Draw lines
1441-
result = func(self, *args, values=values, **kwargs)
1442-
1443-
# Add sticky edges? No because there is no way to check whether "dependent variable"
1444-
# is x or y axis like with area/areax and bar/barh. Better to always have margin.
1445-
# for objs in result:
1446-
# if not isinstance(objs, tuple):
1447-
# objs = (objs,)
1448-
# for obj in objs:
1449-
# xdata = obj.get_xdata()
1450-
# obj.sticky_edges.x.extend((np.min(xdata), np.max(xdata)))
1451-
1452-
return result
1453-
1454-
1455-
@docstring.add_snippets
1456-
def scatter_wrapper(
1457-
self, func, *args,
1458-
s=None, size=None, markersize=None,
1459-
c=None, color=None, markercolor=None, smin=None, smax=None,
1460-
cmap=None, cmap_kw=None, norm=None, norm_kw=None,
1461-
vmin=None, vmax=None, N=None, levels=None, values=None,
1462-
symmetric=False, locator=None, locator_kw=None,
1463-
lw=None, linewidth=None, linewidths=None,
1464-
markeredgewidth=None, markeredgewidths=None,
1465-
edgecolor=None, edgecolors=None,
1466-
markeredgecolor=None, markeredgecolors=None,
1467-
**kwargs
1468-
):
1469-
"""
1470-
Adds keyword arguments to `~matplotlib.axes.Axes.scatter` that are more
1471-
consistent with the `~matplotlib.axes.Axes.plot` keyword arguments and
1472-
supports `cmap_changer` features.
1473-
1474-
Note
1475-
----
1476-
This function wraps {methods}
1477-
1478-
Parameters
1479-
----------
1480-
s, size, markersize : float or list of float, optional
1481-
The marker size(s). The units are scaled by `smin` and `smax`.
1482-
smin, smax : float, optional
1483-
The minimum and maximum marker size in units points ** 2 used to
1484-
scale the `s` array. If not provided, the marker sizes are equivalent
1485-
to the values in the `s` array.
1486-
c, color, markercolor : color-spec or list thereof, or array, optional
1487-
The marker fill color(s). If this is an array of scalar values, the
1488-
colors will be generated by passing the values through the `norm`
1489-
normalizer and drawing from the `cmap` colormap.
1490-
%(axes.cmap_changer)s
1491-
lw, linewidth, linewidths, markeredgewidth, markeredgewidths : \
1492-
float or list thereof, optional
1493-
The marker edge width.
1494-
edgecolors, markeredgecolor, markeredgecolors : \
1495-
color-spec or list thereof, optional
1496-
The marker edge color.
1497-
1498-
Other parameters
1499-
----------------
1500-
**kwargs
1501-
Passed to `~matplotlib.axes.Axes.scatter`.
1502-
"""
1503-
# Manage input arguments
1504-
# NOTE: Parse 1d must come before this
1505-
nargs = len(args)
1506-
if len(args) > 4:
1507-
raise ValueError(f'Expected 1-4 positional args, got {nargs}.')
1508-
args = list(args)
1509-
if len(args) == 4:
1510-
c = args.pop(1)
1511-
if len(args) == 3:
1512-
s = args.pop(0)
1513-
1514-
# Apply some aliases for keyword arguments
1515-
c = _not_none(c=c, color=color, markercolor=markercolor)
1516-
s = _not_none(s=s, size=size, markersize=markersize)
1517-
lw = _not_none(
1518-
lw=lw, linewidth=linewidth, linewidths=linewidths,
1519-
markeredgewidth=markeredgewidth, markeredgewidths=markeredgewidths,
1520-
)
1521-
ec = _not_none(
1522-
edgecolor=edgecolor, edgecolors=edgecolors,
1523-
markeredgecolor=markeredgecolor, markeredgecolors=markeredgecolors,
1524-
)
1525-
1526-
# Get colormap
1527-
cmap_kw = cmap_kw or {}
1528-
if cmap is not None:
1529-
cmap = constructor.Colormap(cmap, **cmap_kw)
1530-
1531-
# Get normalizer and levels
1532-
# NOTE: If the length of the c array !=
1533-
ticks = None
1534-
carray = np.atleast_1d(c)
1535-
if (
1536-
np.issubdtype(carray.dtype, np.number)
1537-
and not (carray.ndim == 2 and carray.shape[1] in (3, 4))
1538-
):
1539-
carray = carray.ravel()
1540-
norm, cmap, _, ticks = _build_discrete_norm(
1541-
carray, # sample data for getting suitable levels
1542-
N=N, levels=levels, values=values,
1543-
norm=norm, norm_kw=norm_kw,
1544-
locator=locator, locator_kw=locator_kw,
1545-
cmap=cmap, vmin=vmin, vmax=vmax, extend='neither',
1546-
symmetric=symmetric,
1547-
)
1548-
1549-
# Fix 2D arguments but still support scatter(x_vector, y_2d) usage
1550-
# NOTE: Since we are flattening vectors the coordinate metadata is meaningless,
1551-
# so converting to ndarray and stripping metadata is no problem.
1552-
# NOTE: numpy.ravel() preserves masked arrays
1553-
if len(args) == 2 and all(np.asarray(arg).squeeze().ndim > 1 for arg in args):
1554-
args = tuple(np.ravel(arg) for arg in args)
1555-
1556-
# Scale s array
1557-
if np.iterable(s) and (smin is not None or smax is not None):
1558-
smin_true, smax_true = min(s), max(s)
1559-
if smin is None:
1560-
smin = smin_true
1561-
if smax is None:
1562-
smax = smax_true
1563-
s = (
1564-
smin + (smax - smin)
1565-
* (np.array(s) - smin_true) / (smax_true - smin_true)
1566-
)
1567-
obj = func(
1568-
self, *args, c=c, s=s, cmap=cmap, norm=norm,
1569-
linewidths=lw, edgecolors=ec, **kwargs
1570-
)
1571-
if ticks is not None:
1572-
obj.ticks = ticks
1573-
return obj
1574-
1575-
15761423
def stem_wrapper(
15771424
self, func, *args, linefmt=None, basefmt=None, markerfmt=None, **kwargs
15781425
):

0 commit comments

Comments
 (0)