Skip to content

Commit c1ffbc8

Browse files
committed
Permit specifying 'linewidth' with arbitrary physical units
1 parent ba32fd1 commit c1ffbc8

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

proplot/internals/__init__.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,21 @@
9090
}
9191

9292

93+
# Unit docstrings
94+
# NOTE: Try to fit this into a single line. Cannot break up with newline as that will
95+
# mess up docstring indentation since this is placed in indented param lines.
96+
_units_docstring = 'If float, units are {units}. If string, interpreted by `~proplot.utils.units`.' # noqa: E501
97+
docstring._snippet_manager['units.pt'] = _units_docstring.format(units='points')
98+
docstring._snippet_manager['units.in'] = _units_docstring.format(units='inches')
99+
docstring._snippet_manager['units.em'] = _units_docstring.format(units='em-widths')
100+
101+
93102
# Style docstrings
94103
# NOTE: These are needed in a few different places
95104
_line_docstring = """
96-
lw, linewidth, linewidths : float, optional
105+
lw, linewidth, linewidths : unit-spec, optional
97106
The width of the line(s). Default is :rc:`lines.linewidth`.
107+
%(units.pt)s
98108
ls, linestyle, linestyles : str, optional
99109
The style of the line(s). Default is :rc:`lines.linestyle`.
100110
c, color, colors : color-spec, optional
@@ -103,8 +113,9 @@
103113
The opacity of the line(s).
104114
"""
105115
_patch_docstring = """
106-
lw, linewidth, linewidths : float, optional
116+
lw, linewidth, linewidths : unit-spec, optional
107117
The edge width of the patch(es). Default is :rc:`patch.linewidth`.
118+
%(units.pt)s
108119
ls, linestyle, linestyles : str, optional
109120
The edge style of the patch(es). Default is ``'-'``.
110121
ec, edgecolor, edgecolors : color-spec, optional
@@ -115,8 +126,9 @@
115126
The opacity of the patch(es).
116127
"""
117128
_pcolor_collection_docstring = """
118-
lw, linewidth, linewidths : float, optional
129+
lw, linewidth, linewidths : unit-spec, optional
119130
The width of lines between grid boxes.
131+
%(units.pt)s
120132
ls, linestyle, linestyles : str, optional
121133
The style of lines between grid boxes.
122134
ec, edgecolor, edgecolors : color-spec, optional
@@ -125,9 +137,10 @@
125137
The opacity of the grid boxes.
126138
"""
127139
_contour_collection_docstring = """
128-
lw, linewidth, linewidths : float, optional
140+
lw, linewidth, linewidths : unit-spec, optional
129141
The width of the contour lines. For `contourf` plots,
130142
lines are added between the filled contours.
143+
%(units.pt)s
131144
ls, linestyle, linestyles : str, optional
132145
The style of the contour lines. For `contourf` plots,
133146
lines are added between the filled contours.
@@ -306,9 +319,13 @@ def _pop_props(input, *categories, prefix=None, ignore=None, skip=None):
306319
if any(string in key for string in ignore):
307320
warnings._warn_proplot(f'Ignoring property {key}={prop!r}.')
308321
continue
309-
if key in ('fontsize',):
310-
from ..config import _fontsize_to_pt
311-
prop = _fontsize_to_pt(prop)
322+
if isinstance(prop, str):
323+
if key in ('fontsize',):
324+
from ..config import _fontsize_to_pt
325+
prop = _fontsize_to_pt(prop)
326+
if key in ('linewidth', 'linewidths', 'markersize'):
327+
from ..utils import units
328+
prop = units(prop, 'pt')
312329
output[key] = prop
313330
return output
314331

proplot/utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@
5656
}
5757

5858

59-
# Unit docstrings
60-
# NOTE: Try to fit this into a single line. Cannot break up with newline as that will
61-
# mess up docstring indentation since this is placed in indented param lines.
62-
_units_docstring = 'If float, units are {units}. If string, interpreted by `~proplot.utils.units`.' # noqa: E501
63-
docstring._snippet_manager['units.pt'] = _units_docstring.format(units='points')
64-
docstring._snippet_manager['units.in'] = _units_docstring.format(units='inches')
65-
docstring._snippet_manager['units.em'] = _units_docstring.format(units='em-widths')
66-
67-
6859
# Color docstrings
6960
_docstring_rgba = """
7061
color : color-spec

0 commit comments

Comments
 (0)