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

+24
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

+19-9
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

+14
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

+1
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

+2-2
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

+3
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

+8
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

+5-4
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

+12
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

+3-6
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

lib/matplotlib/font_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ class FontManager(object):
10411041
# Increment this version number whenever the font cache data
10421042
# format or behavior has changed and requires a existing font
10431043
# cache files to be rebuilt.
1044-
__version__ = 200
1044+
__version__ = 201
10451045

10461046
def __init__(self, size=None, weight='normal'):
10471047
self._version = self.__version__

lib/matplotlib/image.py

+12
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
301301
if A is None:
302302
raise RuntimeError('You must first set the image'
303303
' array or the image attribute')
304+
if any(s == 0 for s in A.shape):
305+
raise RuntimeError("_make_image must get a non-empty image. "
306+
"Your Artist's draw method must filter before "
307+
"this method is called.")
304308

305309
clipped_bbox = Bbox.intersection(out_bbox, clip_bbox)
306310

@@ -478,9 +482,17 @@ def _check_unsampled_image(self, renderer):
478482

479483
@allow_rasterization
480484
def draw(self, renderer, *args, **kwargs):
485+
# if not visible, declare victory and return
481486
if not self.get_visible():
487+
self.stale = False
482488
return
483489

490+
# for empty images, there is nothing to draw!
491+
if self.get_array().size == 0:
492+
self.stale = False
493+
return
494+
495+
# actually render the image.
484496
gc = renderer.new_gc()
485497
self._set_gc_clip(gc)
486498
gc.set_alpha(self.get_alpha())

lib/matplotlib/lines.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ def _get_dash_pattern(style):
6464
def _scale_dashes(offset, dashes, lw):
6565
if not rcParams['lines.scale_dashes']:
6666
return offset, dashes
67-
scale = max(2.0, lw)
67+
6868
scaled_offset = scaled_dashes = None
6969
if offset is not None:
70-
scaled_offset = offset * scale
70+
scaled_offset = offset * lw
7171
if dashes is not None:
72-
scaled_dashes = [x * scale if x is not None else None
72+
scaled_dashes = [x * lw if x is not None else None
7373
for x in dashes]
7474

7575
return scaled_offset, scaled_dashes

lib/matplotlib/patches.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import six
77
from six.moves import map, zip
8+
import warnings
89

910
import math
1011

@@ -113,10 +114,10 @@ def __init__(self,
113114
if antialiased is None:
114115
antialiased = mpl.rcParams['patch.antialiased']
115116

117+
self._hatch_color = colors.to_rgba(mpl.rcParams['hatch.color'])
116118
self._fill = True # needed for set_facecolor call
117119
if color is not None:
118120
if (edgecolor is not None or facecolor is not None):
119-
import warnings
120121
warnings.warn("Setting the 'color' property will override"
121122
"the edgecolor or facecolor properties. ")
122123
self.set_color(color)
@@ -288,13 +289,18 @@ def set_aa(self, aa):
288289
return self.set_antialiased(aa)
289290

290291
def _set_edgecolor(self, color):
292+
set_hatch_color = True
291293
if color is None:
292294
if (mpl.rcParams['patch.force_edgecolor'] or
293295
not self._fill or self._edge_default):
294296
color = mpl.rcParams['patch.edgecolor']
295297
else:
296298
color = 'none'
299+
set_hatch_color = False
300+
297301
self._edgecolor = colors.to_rgba(color, self._alpha)
302+
if set_hatch_color:
303+
self._hatch_color = self._edgecolor
298304
self.stale = True
299305

300306
def set_edgecolor(self, color):
@@ -545,6 +551,12 @@ def draw(self, renderer):
545551

546552
if self._hatch:
547553
gc.set_hatch(self._hatch)
554+
try:
555+
gc.set_hatch_color(self._hatch_color)
556+
except AttributeError:
557+
# if we end up with a GC that does not have this method
558+
warnings.warn("Your backend does not have support for "
559+
"setting the hatch color.")
548560

549561
if self.get_sketch_params() is not None:
550562
gc.set_sketch_params(*self.get_sketch_params())
@@ -4265,6 +4277,13 @@ def draw(self, renderer):
42654277

42664278
if self._hatch:
42674279
gc.set_hatch(self._hatch)
4280+
if self._hatch_color is not None:
4281+
try:
4282+
gc.set_hatch_color(self._hatch_color)
4283+
except AttributeError:
4284+
# if we end up with a GC that does not have this method
4285+
warnings.warn("Your backend does not support setting the "
4286+
"hatch color.")
42684287

42694288
if self.get_sketch_params() is not None:
42704289
gc.set_sketch_params(*self.get_sketch_params())

lib/matplotlib/rcsetup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,9 @@ def _validate_linestyle(ls):
963963
'lines.solid_joinstyle': ['round', validate_joinstyle],
964964
'lines.dash_capstyle': ['butt', validate_capstyle],
965965
'lines.solid_capstyle': ['projecting', validate_capstyle],
966-
'lines.dashed_pattern': [[2.8, 1.2], validate_nseq_float()],
967-
'lines.dashdot_pattern': [[4.8, 1.2, 0.8, 1.2], validate_nseq_float()],
968-
'lines.dotted_pattern': [[1.1, 1.1], validate_nseq_float()],
966+
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float()],
967+
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6], validate_nseq_float()],
968+
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float()],
969969
'lines.scale_dashes': [True, validate_bool],
970970

971971
# marker props

0 commit comments

Comments
 (0)