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

Skip to content

Mrg2.0.x #8110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f6b4a32
FIX: Restore hatch color tracking edge color
tacaswell Jan 28, 2017
a58b0d1
DOC: add whats_new and api_changes entries for gc hatch methods
tacaswell Jan 29, 2017
c2daee2
Fix another datad[cmapname] that didn't exist in master.
QuLogic Jan 30, 2017
a8a769d
Fix grammar of Vega cmap deprecation message.
QuLogic Jan 30, 2017
fbe562c
Merge pull request #7986 from QuLogic/fix-cmap-deprecation
NelleV Jan 30, 2017
98a9347
Merge pull request #7809 from lkilcher/marker_verts_bug
dstansby Jan 30, 2017
8481bc5
Merge pull request #7997 from anntzer/image-tutorial-cmap
dstansby Jan 31, 2017
ab81f13
Test 2.0.x on released python 3.6
dstansby Jan 31, 2017
936315c
Fix broken backported test
dstansby Jan 31, 2017
6b2e116
PEP8
dstansby Jan 31, 2017
c4700bb
FIX: do not try to render empty images
tacaswell Feb 1, 2017
6727dc6
Merge pull request #8004 from dstansby/backport-test-fix
NelleV Feb 1, 2017
654b53b
Merge pull request #8000 from matplotlib/testing-3.6-1
QuLogic Feb 1, 2017
d9742a4
DOC: add missing docs for change to Figure.set_size_inches
tacaswell Feb 2, 2017
493cb8a
Merge pull request #8008 from tacaswell/doc_document_set_size_inches_…
NelleV Feb 2, 2017
48d0ddc
TST: fix test (turns out it is not a context manager)
tacaswell Feb 5, 2017
3ae2ec9
FIX: numpy arrays are not 'truthy'
tacaswell Feb 5, 2017
99de4a7
Bump font cache version.
QuLogic Feb 6, 2017
9c031b9
Merge pull request #8025 from tacaswell/fix_log_subs
NelleV Feb 6, 2017
af37a47
Merge pull request #8029 from QuLogic/fontcache-bump
NelleV Feb 6, 2017
acda4ac
DOC: add missing word
tacaswell Feb 6, 2017
babdf73
MNT: minor tweak to checking size
tacaswell Feb 6, 2017
d63c95d
Merge pull request #7976 from tacaswell/fix_hatch_color
QuLogic Feb 6, 2017
013fd3f
Merge pull request #8006 from tacaswell/fix_imshow_segfault
QuLogic Feb 6, 2017
c43f4fd
FIX: in errorbar discard any kwargs which have None value
tacaswell Feb 6, 2017
e5c3cba
Merge pull request #8033 from shaunwbell/patch-1
tacaswell Feb 7, 2017
9b8b99b
Fixed a small mistake in matplotlibrc.template
rebot Feb 7, 2017
dfd1da5
Merge pull request #8037 from tacaswell/fix_errorbar_color_cycle
dopplershift Feb 8, 2017
f7865d3
Merge pull request #8042 from rebot/patch-1
tacaswell Feb 9, 2017
ac51372
Merge pull request #8070 from heath730/setup_cfg_update
phobson Feb 13, 2017
a347da9
Merge pull request #8084 from jacob-on-github/patch-2
dstansby Feb 16, 2017
1cce7d3
Merge pull request #8086 from mitya57/master
tacaswell Feb 17, 2017
276e1e9
API: Remove lw clipping for dash scaling and tweak pattern
tacaswell Feb 6, 2017
c5a59e3
TST: Tests which require updates due to previous commit
tacaswell Feb 6, 2017
2558530
Merge pull request #8032 from tacaswell/api_lw_scale_clipping
afvincent Feb 17, 2017
35996ce
Merge pull request #8094 from patniharshit/keepmiddle
dstansby Feb 18, 2017
752d6c6
Merge remote-tracking branch 'matplotlib/v2.0.0-doc' into v2.0.x
tacaswell Feb 20, 2017
47fdc32
Merge remote-tracking branch 'matplotlib/v2.0.x'
tacaswell Feb 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ out what caused the breakage and how to fix it by updating your code.
For new features that were added to Matplotlib, please see
:ref:`whats-new`.

API Changes in 2.0.1
====================

Extensions to `matplotlib.backend_bases.GraphicsContextBase`
------------------------------------------------------------

To better support controlling the color of hatches, the method
`matplotlib.backend_bases.GraphicsContextBase.set_hatch_color` was
added to the expected API of ``GraphicsContext`` classes. Calls to
this method are currently wrapped with a ``try:...except Attribute:``
block to preserve back-compatibility with any third-party backends
which do not extend `~matplotlib.backend_bases.GraphicsContextBase`.

This value can be accessed in the backends via
`matplotlib.backend_bases.GraphicsContextBase.get_hatch_color` (which
was added in 2.0 see :ref:`gc_get_hatch_color_wn`) and should be used
to color the hatches.

In the future there may also be ``hatch_linewidth`` and
``hatch_density`` related methods added. It is encouraged, but not
required that third-party backends extend
`~matplotlib.backend_bases.GraphicsContextBase` to make adapting to
these changes easier.


API Changes in 2.0.0
====================
Expand Down
28 changes: 19 additions & 9 deletions doc/users/dflt_style_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ or by setting::

In your :file:`matplotlibrc` file.

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


Plotting functions
==================
Expand Down Expand Up @@ -624,20 +630,24 @@ To restore the previous behavior explicitly pass the keyword argument
Hatching
========

The color and width of the lines in a hatch pattern are now configurable by the
rcParams `hatch.color` and `hatch.linewidth`, with defaults of black and 1
point, respectively. The old behaviour for the color was to apply the edge
color or use black, depending on the artist; the old behavior for the line
width was different depending on backend:

The color of the lines in the hatch is now determined by

- If an edge color is explicitly set, use that for the hatch color
- If the edge color is not explicitly set, use ``rcParam['hatch.color']`` which
is looked up at artist creation time.

The width of the lines in a hatch pattern is now configurable by the
rcParams `hatch.linewidth`, which defaults to 1 point. The old
behavior for the line width was different depending on backend:

- PDF: 0.1 pt
- SVG: 1.0 pt
- PS: 1 px
- Agg: 1 px

The old color behavior can not be restored. The old line width behavior can not
be restored across all backends simultaneously, but can be restored for a
single backend by setting::
The old line width behavior can not be restored across all backends
simultaneously, but can be restored for a single backend by setting::

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


There is no API level control of the hatch color or linewidth.
There is no direct API level control of the hatch color or linewidth.

Hatching patterns are now rendered at a consistent density, regardless of DPI.
Formerly, high DPI figures would be more dense than the default, and low DPI
Expand Down
14 changes: 14 additions & 0 deletions doc/users/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ value of ``None`` instead of ``2``. If ``None`` is given as ``zorder``,
:func:`streamplot` has a default ``zorder`` of
``matplotlib.lines.Line2D.zorder``.

.. _gc_get_hatch_color_wn:

Extension to `matplotlib.backend_bases.GraphicsContextBase`
-----------------------------------------------------------

To support standardizing hatch behavior across the backends we ship
the `matplotlib.backend_bases.GraphicsContextBase.get_hatch_color`
method as added to `matplotlib.backend_bases.GraphicsContextBase`.
This is only used during the render process in the backends we ship so
will not break any third-party backends.

If you maintain a third-party backend which extends
`~matplotlib.backend_bases.GraphicsContextBase` this method is now
available to you and should be used to color hatch patterns.

Previous Whats New
==================
Expand Down
1 change: 1 addition & 0 deletions examples/pylab_examples/matshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def samplemat(dims):
aa[i, i] = i
return aa


# Display matrix
plt.matshow(samplemat((15, 35)))

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,8 +1384,8 @@ def __getitem__(self, key):
"Vega20b_r", "Vega20c", "Vega20c_r"]:
warn_deprecated(
"2.0",
name="Vega colormaps",
alternative="tab",
name=key,
alternative="tab" + key[4:],
obj_type="colormap"
)

Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2798,6 +2798,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
.. plot:: mpl_examples/statistics/errorbar_demo.py
"""
kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
# anything that comes in as 'None', drop so the default thing
# happens down stream
kwargs = {k: v for k, v in kwargs.items() if v is not None}
kwargs.setdefault('zorder', 2)

if errorevery < 1:
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@ def copy_properties(self, gc):
self._linewidth = gc._linewidth
self._rgb = gc._rgb
self._hatch = gc._hatch
self._hatch_color = gc._hatch_color
self._hatch_linewidth = gc._hatch_linewidth
self._url = gc._url
self._gid = gc._gid
self._snap = gc._snap
Expand Down Expand Up @@ -1123,6 +1125,12 @@ def get_hatch_color(self):
"""
return self._hatch_color

def set_hatch_color(self, hatch_color):
"""
sets the color to use for hatching.
"""
self._hatch_color = hatch_color

def get_hatch_linewidth(self):
"""
Gets the linewidth to use for hatching.
Expand Down
9 changes: 5 additions & 4 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2253,14 +2253,14 @@ def alpha_cmd(self, alpha, forced, effective_alphas):
name = self.file.alphaState(effective_alphas)
return [name, Op.setgstate]

def hatch_cmd(self, hatch):
def hatch_cmd(self, hatch, hatch_color):
if not hatch:
if self._fillcolor is not None:
return self.fillcolor_cmd(self._fillcolor)
else:
return [Name('DeviceRGB'), Op.setcolorspace_nonstroke]
else:
hatch_style = (self._hatch_color, self._fillcolor, hatch)
hatch_style = (hatch_color, self._fillcolor, hatch)
name = self.file.hatchPattern(hatch_style)
return [Name('Pattern'), Op.setcolorspace_nonstroke,
name, Op.setcolor_nonstroke]
Expand Down Expand Up @@ -2324,7 +2324,8 @@ def clip_cmd(self, cliprect, clippath):
(('_linewidth',), linewidth_cmd),
(('_dashes',), dash_cmd),
(('_rgb',), rgb_cmd),
(('_hatch',), hatch_cmd), # must come after fillcolor and rgb
# must come after fillcolor and rgb
(('_hatch', '_hatch_color'), hatch_cmd),
)

# TODO: _linestyle
Expand Down Expand Up @@ -2355,7 +2356,7 @@ def delta(self, other):
break

# Need to update hatching if we also updated fillcolor
if params == ('_hatch',) and fill_performed:
if params == ('_hatch', '_hatch_color') and fill_performed:
different = True

if different:
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def __init__(self,
self._linewidths = [0]
self._is_filled = True # May be modified by set_facecolor().

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

if self._hatch:
gc.set_hatch(self._hatch)
try:
gc.set_hatch_color(self._hatch_color)
except AttributeError:
# if we end up with a GC that does not have this method
warnings.warn("Your backend does not support setting the "
"hatch color.")

if self.get_sketch_params() is not None:
gc.set_sketch_params(*self.get_sketch_params())
Expand Down Expand Up @@ -648,12 +655,15 @@ def get_edgecolor(self):
get_edgecolors = get_edgecolor

def _set_edgecolor(self, c):
set_hatch_color = True
if c is None:
if (mpl.rcParams['patch.force_edgecolor'] or
not self._is_filled or self._edge_default):
c = mpl.rcParams['patch.edgecolor']
else:
c = 'none'
set_hatch_color = False

self._is_stroked = True
try:
if c.lower() == 'none':
Expand All @@ -668,6 +678,8 @@ def _set_edgecolor(self, c):
except AttributeError:
pass
self._edgecolors = mcolors.to_rgba_array(c, self._alpha)
if set_hatch_color and len(self._edgecolors):
self._hatch_color = tuple(self._edgecolors[0])
self.stale = True

def set_edgecolor(self, c):
Expand Down
9 changes: 3 additions & 6 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,12 @@ def figimage(self, X,
return im

def set_size_inches(self, w, h=None, forward=True):
"""
set_size_inches(w,h, forward=False)

Set the figure size in inches (1in == 2.54cm)
"""Set the figure size in inches (1in == 2.54cm)

Usage::
Usage ::

fig.set_size_inches(w,h) # OR
fig.set_size_inches((w,h) )
fig.set_size_inches((w,h))

optional kwarg *forward=True* will cause the canvas size to be
automatically updated; e.g., you can resize the figure window
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ class FontManager(object):
# Increment this version number whenever the font cache data
# format or behavior has changed and requires a existing font
# cache files to be rebuilt.
__version__ = 200
__version__ = 201

def __init__(self, size=None, weight='normal'):
self._version = self.__version__
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
if A is None:
raise RuntimeError('You must first set the image'
' array or the image attribute')
if any(s == 0 for s in A.shape):
raise RuntimeError("_make_image must get a non-empty image. "
"Your Artist's draw method must filter before "
"this method is called.")

clipped_bbox = Bbox.intersection(out_bbox, clip_bbox)

Expand Down Expand Up @@ -478,9 +482,17 @@ def _check_unsampled_image(self, renderer):

@allow_rasterization
def draw(self, renderer, *args, **kwargs):
# if not visible, declare victory and return
if not self.get_visible():
self.stale = False
return

# for empty images, there is nothing to draw!
if self.get_array().size == 0:
self.stale = False
return

# actually render the image.
gc = renderer.new_gc()
self._set_gc_clip(gc)
gc.set_alpha(self.get_alpha())
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def _get_dash_pattern(style):
def _scale_dashes(offset, dashes, lw):
if not rcParams['lines.scale_dashes']:
return offset, dashes
scale = max(2.0, lw)

scaled_offset = scaled_dashes = None
if offset is not None:
scaled_offset = offset * scale
scaled_offset = offset * lw
if dashes is not None:
scaled_dashes = [x * scale if x is not None else None
scaled_dashes = [x * lw if x is not None else None
for x in dashes]

return scaled_offset, scaled_dashes
Expand Down
21 changes: 20 additions & 1 deletion lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import six
from six.moves import map, zip
import warnings

import math

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

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

def _set_edgecolor(self, color):
set_hatch_color = True
if color is None:
if (mpl.rcParams['patch.force_edgecolor'] or
not self._fill or self._edge_default):
color = mpl.rcParams['patch.edgecolor']
else:
color = 'none'
set_hatch_color = False

self._edgecolor = colors.to_rgba(color, self._alpha)
if set_hatch_color:
self._hatch_color = self._edgecolor
self.stale = True

def set_edgecolor(self, color):
Expand Down Expand Up @@ -545,6 +551,12 @@ def draw(self, renderer):

if self._hatch:
gc.set_hatch(self._hatch)
try:
gc.set_hatch_color(self._hatch_color)
except AttributeError:
# if we end up with a GC that does not have this method
warnings.warn("Your backend does not have support for "
"setting the hatch color.")

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

if self._hatch:
gc.set_hatch(self._hatch)
if self._hatch_color is not None:
try:
gc.set_hatch_color(self._hatch_color)
except AttributeError:
# if we end up with a GC that does not have this method
warnings.warn("Your backend does not support setting the "
"hatch color.")

if self.get_sketch_params() is not None:
gc.set_sketch_params(*self.get_sketch_params())
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,9 @@ def _validate_linestyle(ls):
'lines.solid_joinstyle': ['round', validate_joinstyle],
'lines.dash_capstyle': ['butt', validate_capstyle],
'lines.solid_capstyle': ['projecting', validate_capstyle],
'lines.dashed_pattern': [[2.8, 1.2], validate_nseq_float()],
'lines.dashdot_pattern': [[4.8, 1.2, 0.8, 1.2], validate_nseq_float()],
'lines.dotted_pattern': [[1.1, 1.1], validate_nseq_float()],
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float()],
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6], validate_nseq_float()],
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float()],
'lines.scale_dashes': [True, validate_bool],

# marker props
Expand Down
Loading