Skip to content

Commit e69ea36

Browse files
authored
Merge pull request matplotlib#8110 from tacaswell/mrg2.0.x
Mrg2.0.x
2 parents 8241344 + 47fdc32 commit e69ea36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+998
-360
lines changed

doc/api/api_changes.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@ out what caused the breakage and how to fix it by updating your code.
1010
For new features that were added to Matplotlib, please see
1111
:ref:`whats-new`.
1212

13+
API Changes in 2.0.1
14+
====================
15+
16+
Extensions to `matplotlib.backend_bases.GraphicsContextBase`
17+
------------------------------------------------------------
18+
19+
To better support controlling the color of hatches, the method
20+
`matplotlib.backend_bases.GraphicsContextBase.set_hatch_color` was
21+
added to the expected API of ``GraphicsContext`` classes. Calls to
22+
this method are currently wrapped with a ``try:...except Attribute:``
23+
block to preserve back-compatibility with any third-party backends
24+
which do not extend `~matplotlib.backend_bases.GraphicsContextBase`.
25+
26+
This value can be accessed in the backends via
27+
`matplotlib.backend_bases.GraphicsContextBase.get_hatch_color` (which
28+
was added in 2.0 see :ref:`gc_get_hatch_color_wn`) and should be used
29+
to color the hatches.
30+
31+
In the future there may also be ``hatch_linewidth`` and
32+
``hatch_density`` related methods added. It is encouraged, but not
33+
required that third-party backends extend
34+
`~matplotlib.backend_bases.GraphicsContextBase` to make adapting to
35+
these changes easier.
36+
1337

1438
API Changes in 2.0.0
1539
====================

doc/users/dflt_style_changes.rst

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ or by setting::
256256

257257
In your :file:`matplotlibrc` file.
258258

259+
In addition, the ``forward`` kwarg to
260+
`~matplotlib.Figure.set_size_inches` now defaults to `True` to improve
261+
the interactive experience. Backend canvases that adjust the size of
262+
their bound `matplotlib.figure.Figure` must pass ``forward=False`` to
263+
avoid circular behavior. This default is not configurable.
264+
259265

260266
Plotting functions
261267
==================
@@ -624,20 +630,24 @@ To restore the previous behavior explicitly pass the keyword argument
624630
Hatching
625631
========
626632

627-
The color and width of the lines in a hatch pattern are now configurable by the
628-
rcParams `hatch.color` and `hatch.linewidth`, with defaults of black and 1
629-
point, respectively. The old behaviour for the color was to apply the edge
630-
color or use black, depending on the artist; the old behavior for the line
631-
width was different depending on backend:
633+
634+
The color of the lines in the hatch is now determined by
635+
636+
- If an edge color is explicitly set, use that for the hatch color
637+
- If the edge color is not explicitly set, use ``rcParam['hatch.color']`` which
638+
is looked up at artist creation time.
639+
640+
The width of the lines in a hatch pattern is now configurable by the
641+
rcParams `hatch.linewidth`, which defaults to 1 point. The old
642+
behavior for the line width was different depending on backend:
632643

633644
- PDF: 0.1 pt
634645
- SVG: 1.0 pt
635646
- PS: 1 px
636647
- Agg: 1 px
637648

638-
The old color behavior can not be restored. The old line width behavior can not
639-
be restored across all backends simultaneously, but can be restored for a
640-
single backend by setting::
649+
The old line width behavior can not be restored across all backends
650+
simultaneously, but can be restored for a single backend by setting::
641651

642652
mpl.rcParams['hatch.linewidth'] = 0.1 # previous pdf hatch linewidth
643653
mpl.rcParams['hatch.linewidth'] = 1.0 # previous svg hatch linewidth
@@ -650,7 +660,7 @@ The behavior of the PS and Agg backends was DPI dependent, thus::
650660
mpl.rcParams['hatch.linewidth'] = 1.0 / dpi # previous ps and Agg hatch linewidth
651661

652662

653-
There is no API level control of the hatch color or linewidth.
663+
There is no direct API level control of the hatch color or linewidth.
654664

655665
Hatching patterns are now rendered at a consistent density, regardless of DPI.
656666
Formerly, high DPI figures would be more dense than the default, and low DPI

doc/users/whats_new.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,20 @@ value of ``None`` instead of ``2``. If ``None`` is given as ``zorder``,
313313
:func:`streamplot` has a default ``zorder`` of
314314
``matplotlib.lines.Line2D.zorder``.
315315

316+
.. _gc_get_hatch_color_wn:
317+
318+
Extension to `matplotlib.backend_bases.GraphicsContextBase`
319+
-----------------------------------------------------------
320+
321+
To support standardizing hatch behavior across the backends we ship
322+
the `matplotlib.backend_bases.GraphicsContextBase.get_hatch_color`
323+
method as added to `matplotlib.backend_bases.GraphicsContextBase`.
324+
This is only used during the render process in the backends we ship so
325+
will not break any third-party backends.
326+
327+
If you maintain a third-party backend which extends
328+
`~matplotlib.backend_bases.GraphicsContextBase` this method is now
329+
available to you and should be used to color hatch patterns.
316330

317331
Previous Whats New
318332
==================

examples/pylab_examples/matshow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def samplemat(dims):
1010
aa[i, i] = i
1111
return aa
1212

13+
1314
# Display matrix
1415
plt.matshow(samplemat((15, 35)))
1516

lib/matplotlib/_cm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,8 @@ def __getitem__(self, key):
13841384
"Vega20b_r", "Vega20c", "Vega20c_r"]:
13851385
warn_deprecated(
13861386
"2.0",
1387-
name="Vega colormaps",
1388-
alternative="tab",
1387+
name=key,
1388+
alternative="tab" + key[4:],
13891389
obj_type="colormap"
13901390
)
13911391

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
27982798
.. plot:: mpl_examples/statistics/errorbar_demo.py
27992799
"""
28002800
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
2801+
# anything that comes in as 'None', drop so the default thing
2802+
# happens down stream
2803+
kwargs = {k: v for k, v in kwargs.items() if v is not None}
28012804
kwargs.setdefault('zorder', 2)
28022805

28032806
if errorevery < 1:

lib/matplotlib/backend_bases.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ def copy_properties(self, gc):
838838
self._linewidth = gc._linewidth
839839
self._rgb = gc._rgb
840840
self._hatch = gc._hatch
841+
self._hatch_color = gc._hatch_color
842+
self._hatch_linewidth = gc._hatch_linewidth
841843
self._url = gc._url
842844
self._gid = gc._gid
843845
self._snap = gc._snap
@@ -1123,6 +1125,12 @@ def get_hatch_color(self):
11231125
"""
11241126
return self._hatch_color
11251127

1128+
def set_hatch_color(self, hatch_color):
1129+
"""
1130+
sets the color to use for hatching.
1131+
"""
1132+
self._hatch_color = hatch_color
1133+
11261134
def get_hatch_linewidth(self):
11271135
"""
11281136
Gets the linewidth to use for hatching.

lib/matplotlib/backends/backend_pdf.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,14 +2253,14 @@ def alpha_cmd(self, alpha, forced, effective_alphas):
22532253
name = self.file.alphaState(effective_alphas)
22542254
return [name, Op.setgstate]
22552255

2256-
def hatch_cmd(self, hatch):
2256+
def hatch_cmd(self, hatch, hatch_color):
22572257
if not hatch:
22582258
if self._fillcolor is not None:
22592259
return self.fillcolor_cmd(self._fillcolor)
22602260
else:
22612261
return [Name('DeviceRGB'), Op.setcolorspace_nonstroke]
22622262
else:
2263-
hatch_style = (self._hatch_color, self._fillcolor, hatch)
2263+
hatch_style = (hatch_color, self._fillcolor, hatch)
22642264
name = self.file.hatchPattern(hatch_style)
22652265
return [Name('Pattern'), Op.setcolorspace_nonstroke,
22662266
name, Op.setcolor_nonstroke]
@@ -2324,7 +2324,8 @@ def clip_cmd(self, cliprect, clippath):
23242324
(('_linewidth',), linewidth_cmd),
23252325
(('_dashes',), dash_cmd),
23262326
(('_rgb',), rgb_cmd),
2327-
(('_hatch',), hatch_cmd), # must come after fillcolor and rgb
2327+
# must come after fillcolor and rgb
2328+
(('_hatch', '_hatch_color'), hatch_cmd),
23282329
)
23292330

23302331
# TODO: _linestyle
@@ -2355,7 +2356,7 @@ def delta(self, other):
23552356
break
23562357

23572358
# Need to update hatching if we also updated fillcolor
2358-
if params == ('_hatch',) and fill_performed:
2359+
if params == ('_hatch', '_hatch_color') and fill_performed:
23592360
different = True
23602361

23612362
if different:

lib/matplotlib/collections.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def __init__(self,
131131
self._linewidths = [0]
132132
self._is_filled = True # May be modified by set_facecolor().
133133

134+
self._hatch_color = mcolors.to_rgba(mpl.rcParams['hatch.color'])
134135
self.set_facecolor(facecolors)
135136
self.set_edgecolor(edgecolors)
136137
self.set_linewidth(linewidths)
@@ -260,6 +261,12 @@ def draw(self, renderer):
260261

261262
if self._hatch:
262263
gc.set_hatch(self._hatch)
264+
try:
265+
gc.set_hatch_color(self._hatch_color)
266+
except AttributeError:
267+
# if we end up with a GC that does not have this method
268+
warnings.warn("Your backend does not support setting the "
269+
"hatch color.")
263270

264271
if self.get_sketch_params() is not None:
265272
gc.set_sketch_params(*self.get_sketch_params())
@@ -648,12 +655,15 @@ def get_edgecolor(self):
648655
get_edgecolors = get_edgecolor
649656

650657
def _set_edgecolor(self, c):
658+
set_hatch_color = True
651659
if c is None:
652660
if (mpl.rcParams['patch.force_edgecolor'] or
653661
not self._is_filled or self._edge_default):
654662
c = mpl.rcParams['patch.edgecolor']
655663
else:
656664
c = 'none'
665+
set_hatch_color = False
666+
657667
self._is_stroked = True
658668
try:
659669
if c.lower() == 'none':
@@ -668,6 +678,8 @@ def _set_edgecolor(self, c):
668678
except AttributeError:
669679
pass
670680
self._edgecolors = mcolors.to_rgba_array(c, self._alpha)
681+
if set_hatch_color and len(self._edgecolors):
682+
self._hatch_color = tuple(self._edgecolors[0])
671683
self.stale = True
672684

673685
def set_edgecolor(self, c):

lib/matplotlib/figure.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,15 +679,12 @@ def figimage(self, X,
679679
return im
680680

681681
def set_size_inches(self, w, h=None, forward=True):
682-
"""
683-
set_size_inches(w,h, forward=False)
684-
685-
Set the figure size in inches (1in == 2.54cm)
682+
"""Set the figure size in inches (1in == 2.54cm)
686683
687-
Usage::
684+
Usage ::
688685
689686
fig.set_size_inches(w,h) # OR
690-
fig.set_size_inches((w,h) )
687+
fig.set_size_inches((w,h))
691688
692689
optional kwarg *forward=True* will cause the canvas size to be
693690
automatically updated; e.g., you can resize the figure window

0 commit comments

Comments
 (0)