8000 Backport PR #15271 on branch v3.1.x by timhoffm · Pull Request #15277 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #15271 on branch v3.1.x #15277

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ab203bd
Backport PR #14919: FIX constrained_layout w/ hidden axes
anntzer Aug 12, 2019
4a4980b
Merge pull request #15047 from meeseeksmachine/auto-backport-of-pr-14…
dstansby Aug 13, 2019
c3fd5c0
Backport PR #15055: Remove mention of now-removed feature in docstring.
timhoffm Aug 14, 2019
5685acb
Merge pull request #15058 from meeseeksmachine/auto-backport-of-pr-15…
dstansby Aug 14, 2019
0749a08
Backport PR #15114: DOC: update language around NF
anntzer Aug 23, 2019
9597141
Merge pull request #15116 from meeseeksmachine/auto-backport-of-pr-15…
tacaswell Aug 23, 2019
4a801e7
Backport PR #15110: Add inheritance diagram to mpl.ticker docs
timhoffm Aug 25, 2019
aea1b35
Merge pull request #15125 from meeseeksmachine/auto-backport-of-pr-15…
timhoffm Aug 25, 2019
411618a
Backport PR #15115: Doc: highlight rcparams
tacaswell Aug 26, 2019
8cdf5b8
Merge pull request #15128 from meeseeksmachine/auto-backport-of-pr-15…
tacaswell Aug 26, 2019
72ba424
Backport PR #15132: Update documenting guide on rcParams
QuLogic Aug 27, 2019
6caf7d8
Merge pull request #15135 from meeseeksmachine/auto-backport-of-pr-15…
tacaswell Aug 27, 2019
9cb2251
Backport PR #14456: PyQT5 Backend Partial Redraw Fix
anntzer Aug 29, 2019
f588 8000 373
Merge pull request #15153 from meeseeksmachine/auto-backport-of-pr-14…
timhoffm Aug 29, 2019
dcb48c3
Merge pull request #15166 from jklymak/fix-indexed-pandas-bar
dstansby Sep 2, 2019
169a9f7
Merge pull request #15172 from dstansby/backport-15166
NelleV Sep 2, 2019
5c4a79b
Backport PR #15181: FIX: proper call to zero_formats
tacaswell Sep 4, 2019
ba89a16
Merge pull request #15183 from meeseeksmachine/auto-backport-of-pr-15…
jklymak Sep 4, 2019
4651a12
Backport PR #15168: MNT: explicitly cast np.bool_ -> bool to prevent …
jklymak Sep 4, 2019
2ccd085
Merge pull request #15140 from dstansby/mask-fmt
tacaswell Aug 28, 2019
1191549
Merge pull request #15185 from meeseeksmachine/auto-backport-of-pr-15…
tacaswell Sep 4, 2019
c615fd4
Merge pull request #15187 from dstansby/15140-backport
tacaswell Sep 4, 2019
cc90c15
Backport PR #14979: FIX: Don't enable IPython integration if not ente…
anntzer Aug 9, 2019
56f2946
Backport PR #14683: For non-html output, let sphinx pick the best format
tacaswell Jul 5, 2019
f624bcd
Merge pull request #15190 from tacaswell/auto-backport-of-pr-14683-on…
dstansby Sep 5, 2019
c536fb6
Merge pull request #15189 from tacaswell/auto-backport-of-pr-14979-on…
dstansby Sep 5, 2019
fce83e8
Backport PR #15197: Remove mention of now-removed basedir setup option.
tacaswell Sep 5, 2019
39d4010
Merge pull request #15198 from meeseeksmachine/auto-backport-of-pr-15…
tacaswell Sep 6, 2019
3ba761f
Backport PR #15206: FIX: be more forgiving about expecting internal s…
dstansby Sep 6, 2019
bc75f0b
Merge pull request #15207 from tacaswell/auto-backport-of-pr-15206-on…
QuLogic Sep 7, 2019
101157a
Backport PR #15217: Doc: Add `plt.show()` to horizontal bar chart exa…
meeseeksmachine Sep 8, 2019
67b4ee2
Backport PR #15271: Fix font weight validation
QuLogic Sep 16, 2019
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Thumbs.db
###################################
lib/matplotlib/mpl-data/matplotlib.conf
lib/matplotlib/mpl-data/matplotlibrc
tutorials/intermediate/CL01.png
tutorials/intermediate/CL02.png

# Documentation generated files #
#################################
Expand Down
7 changes: 0 additions & 7 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ file will be particularly useful to those packaging Matplotlib.

.. _setup.cfg: https://raw.githubusercontent.com/matplotlib/matplotlib/master/setup.cfg.template

If you have installed prerequisites to nonstandard places and need to
inform Matplotlib where they are, edit ``setupext.py`` and add the base
dirs to the ``basedir`` dictionary entry for your ``sys.platform``;
e.g., if the header of some required library is in
``/some/path/include/someheader.h``, put ``/some/path`` in the
``basedir`` list for your platform.

.. _install_requirements:

Dependencies
Expand Down
4 changes: 4 additions & 0 deletions doc/_static/mpl.css
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ span.linkdescr {
font-size: 90%;
}

.highlight span.c1 span.highlighted {
background-color: #fce5a6;
}

ul.search {
margin: 10px 0 0 20px;
padding: 0;
Expand Down
4 changes: 4 additions & 0 deletions doc/api/ticker_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
:members:
:undoc-members:
:show-inheritance:


.. inheritance-diagram:: matplotlib.ticker
:parts: 1
11 changes: 2 additions & 9 deletions doc/devel/documenting_mpl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -500,15 +500,8 @@ section of the docstring.
rcParams
~~~~~~~~
rcParams can be referenced with the custom ``:rc:`` role:
:literal:`:rc:\`foo\`` yields ``rcParams["foo"]``. Use `= [default-val]`
to indicate the default value of the parameter. The default value should be
literal, i.e. enclosed in double backticks. For simplicity these may be
omitted for string default values.

.. code-block:: rst

If not provided, defaults to :rc:`figure.figsize` = ``[6.4, 4.8]``.
If not provided, defaults to :rc:`figure.facecolor` = 'w'.
:literal:`:rc:\`foo\`` yields ``rcParams["foo"] = 'default'``, which is a link
to the :file:`matplotlibrc` file description.

Deprecated formatting conventions
---------------------------------
Expand Down
13 changes: 13 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,25 @@ Open source
style="float:right; margin-left:20px" />
</a>


Matplotlib is a Sponsored Project of NumFOCUS, a 501(c)(3) nonprofit
charity in the United States. NumFOCUS provides Matplotlib with
fiscal, legal, and administrative support to help ensure the health
and sustainability of the project. Visit `numfocus.org <nf>`_ for more
information.

Donations to Matplotlib are managed by NumFOCUS. For donors in the
United States, your gift is tax-deductible to the extent provided by
law. As with any donation, you should consult with your tax adviser
about your particular tax situation.

Please consider `donating to the Matplotlib project <donating_>`_ through
the Numfocus organization or to the `John Hunter Technology Fellowship
<jdh-fellowship_>`_.

.. _donating: https://numfocus.salsalabs.org/donate-to-matplotlib/index.html
.. _jdh-fellowship: https://www.numfocus.org/programs/john-hunter-technology-fellowship/
.. _nf: https://numfocus.org

The :doc:`Matplotlib license <users/license>` is based on the `Python Software
Foundation (PSF) license <psf-license_>`_.
Expand Down
7 changes: 5 additions & 2 deletions doc/sphinxext/custom_roles.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from docutils import nodes
from os.path import sep
from matplotlib import rcParamsDefault


def rcparam_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
rendered = nodes.Text('rcParams["{}"]'.format(text))
param = rcParamsDefault.get(text)
rendered = nodes.Text(f'rcParams["{text}"] = {param!r}')

source = inliner.document.attributes['source'].replace(sep, '/')
rel_source = source.split('/doc/', 1)[1]

levels = rel_source.count('/')
refuri = ('../' * levels +
'tutorials/introductory/customizing.html#matplotlib-rcparams')
'tutorials/introductory/customizing.html' +
f"?highlight={text}#a-sample-matplotlibrc-file")

ref = nodes.reference(rawtext, rendered, refuri=refuri)
return [nodes.literal('', '', ref)], []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def survey(results, category_names):


survey(results, category_names)
plt.show()

#############################################################################
#
Expand Down
6 changes: 5 additions & 1 deletion lib/matplotlib/_constrained_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ def _make_layout_margins(ax, renderer, h_pad, w_pad):
invTransFig = fig.transFigure.inverted().transform_bbox
pos = ax.get_position(original=True)
tightbbox = ax.get_tightbbox(renderer=renderer)
bbox = invTransFig(tightbbox)
if tightbbox is None:
bbox = pos
else:
bbox = invTransFig(tightbbox)

# this can go wrong:
if not (np.isfinite(bbox.width) and np.isfinite(bbox.height)):
# just abort, this is likely a bad set of co-ordinates that
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2163,12 +2163,12 @@ def _convert_dx(dx, x0, xconv, convert):
# removes the units from unit packages like `pint` that
# wrap numpy arrays.
try:
x0 = x0[0]
x0 = cbook.safe_first_element(x0)
except (TypeError, IndexError, KeyError):
x0 = x0

try:
x = xconv[0]
x = cbook.safe_first_element(xconv)
except (TypeError, IndexError, KeyError):
x = xconv

Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3267,7 +3267,8 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
reverse = left > right
left, right = self.xaxis.get_major_locator().nonsingular(left, right)
left, right = self.xaxis.limit_range_for_scale(left, right)
left, right = sorted([left, right], reverse=reverse)
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
left, right = sorted([left, right], reverse=bool(reverse))

self.viewLim.intervalx = (left, right)
if auto is not None:
Expand Down Expand Up @@ -3649,7 +3650,8 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
reverse = bottom > top
bottom, top = self.yaxis.get_major_locator().nonsingular(bottom, top)
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
bottom, top = sorted([bottom, top], reverse=reverse)
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
bottom, top = sorted([bottom, top], reverse=bool(reverse))

self.viewLim.intervaly = (bottom, top)
if auto is not None:
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,8 @@ def get_minpos(self):
def set_inverted(self, inverted):
# docstring inherited
a, b = self.get_view_interval()
self.axes.set_xlim(sorted((a, b), reverse=inverted), auto=None)
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
self.axes.set_xlim(sorted((a, b), reverse=bool(inverted)), auto=None)

def set_default_intervals(self):
# docstring inherited
Expand Down Expand Up @@ -2463,7 +2464,8 @@ def get_minpos(self):
def set_inverted(self, inverted):
# docstring inherited
a, b = self.get_view_interval()
self.axes.set_ylim(sorted((a, b), reverse=inverted), auto=None)
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
self.axes.set_ylim(sorted((a, b), reverse=bool(inverted)), auto=None)

def set_default_intervals(self):
# docstring inherited
Expand Down
25 changes: 16 additions & 9 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,20 @@ def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None):
self.key = key


def _is_non_interactive_terminal_ipython(ip):
"""
Return whether we are in a a terminal IPython, but non interactive.

When in _terminal_ IPython, ip.parent will have and `interact` attribute,
if this attribute is False we do not setup eventloop integration as the
user will _not_ interact with IPython. In all other case (ZMQKernel, or is
interactive), we do.
"""
return (hasattr(ip, 'parent')
and (ip.parent is not None)
and getattr(ip.parent, 'interact', None) is False)


class FigureCanvasBase(object):
"""
The canvas the figure renders into.
Expand Down Expand Up @@ -1620,15 +1634,8 @@ def _fix_ipython_backend2gui(cls):
backend2gui_rif = {"qt5": "qt", "qt4": "qt", "gtk3": "gtk3",
"wx": "wx", "macosx": "osx"}.get(rif)
if backend2gui_rif:
pt.backend2gui[get_backend()] = backend2gui_rif
# Work around pylabtools.find_gui_and_backend always reading from
# rcParamsOrig.
orig_origbackend = mpl.rcParamsOrig["backend"]
try:
mpl.rcParamsOrig["backend"] = mpl.rcParams["backend"]
ip.enable_matplotlib()
finally:
mpl.rcParamsOrig["backend"] = orig_origbackend
if _is_non_interactive_terminal_ipython(ip):
ip.enable_gui(backend2gui_rif)

@contextmanager
def _idle_draw_cntx(self):
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ def draw_idle(self):
# current event loop in order to ensure thread affinity and to
# accumulate multiple draw requests from event handling.
# TODO: queued signal connection might be safer than singleShot
if not (self._draw_pending or self._is_drawing):
if not (getattr(self, '_draw_pending', False) or
getattr(self, '._is_drawing', False)):
self._draw_pending = True
QtCore.QTimer.singleShot(0, self._draw_idle)

Expand Down
26 changes: 16 additions & 10 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ def paintEvent(self, event):

painter = QtGui.QPainter(self)

rect = event.rect()
left = rect.left()
top = rect.top()
width = rect.width()
height = rect.height()
# See documentation of QRect: bottom() and right() are off by 1, so use
# left() + width() and top() + height().
bbox = Bbox(
[[left, self.renderer.height - (top + height * self._dpi_ratio)],
[left + width * self._dpi_ratio, self.renderer.height - top]])
rect = event.rect()
# scale rect dimensions using the screen dpi ratio to get
# correct values for the Figure coordinates (rather than QT5's coords)
width = rect.width() * self._dpi_ratio
height = rect.height() * self._dpi_ratio
left, top = self.mouseEventCoords(rect.topLeft())
# shift the "top" by the height of the image to get the
# correct corner for our coordinate system
bottom = top - height
# same with the right side of the image
right = left + width
# create a buffer using the image bounding box
bbox = Bbox([[left, bottom], [right, top]])
reg = self.copy_from_bbox(bbox)
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
memoryview(reg))
Expand All @@ -60,8 +65,9 @@ def paintEvent(self, event):
if hasattr(qimage, 'setDevicePixelRatio'):
# Not available on Qt4 or some older Qt5.
qimage.setDevicePixelRatio(self._dpi_ratio)
origin = QtCore.QPoint(left, top)
painter.drawImage(origin / self._dpi_ratio, qimage)
# set origin using original QT coordinates
origin = QtCore.QPoint(rect.left(), rect.top())
painter.drawImage(origin, qimage)
# Adjust the buf reference count to work around a memory
# leak bug in QImage under PySide on Python 3.
if QT_API in ('PySide', 'PySide2'):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def __init__(self, locator, tz=None, formats=None, offset_formats=None,
# like 1 Jan can just be labled "Jan". 02:02:00 can
# just be labeled 02:02.
if zero_formats:
if len(formats) != 6:
if len(zero_formats) != 6:
raise ValueError('zero_formats argument must be a list of '
'6 format strings (or None)')
self.zero_formats = zero_formats
Expand Down
9 changes: 1 addition & 8 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,21 +790,14 @@ def axes(arg=None, **kwargs):

Parameters
----------
arg : { None, 4-tuple, Axes }
arg : None or 4-tuple
The exact behavior of this function depends on the type:

- *None*: A new full window axes is added using
``subplot(111, **kwargs)``
- 4-tuple of floats *rect* = ``[left, bottom, width, height]``.
A new axes is added with dimensions *rect* in normalized
(0, 1) units using `~.Figure.add_axes` on the current figure.
- `~.axes.Axes`: This is equivalent to `.pyplot.sca`.
It sets the current axes to *arg*. Note: This implicitly
changes the current figure to the parent of *arg*.

.. note:: The use of an `.axes.Axes` as an argument is deprecated
and will be removed in v3.0. Please use `.pyplot.sca`
instead.

projection : {None, 'aitoff', 'hammer', 'lambert', 'mollweide', \
'polar', 'rectilinear', str}, optional
Expand Down
21 changes: 17 additions & 4 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,19 @@ def validate_fontsize(s):
validate_fontsizelist = _listify_validator(validate_fontsize)


def validate_fontweight(s):
weights = [
'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman',
'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black']
# Note: Historically, weights have been case-sensitive in Matplotlib
if s in weights:
return s
try:
return int(s)
except (ValueError, TypeError):
raise ValueError(f'{s} is not a valid font weight. %s')


def validate_font_properties(s):
parse_fontconfig_pattern(s)
return s
Expand Down Expand Up @@ -1113,7 +1126,7 @@ def _validate_linestyle(ls):
'font.style': ['normal', validate_string],
'font.variant': ['normal', validate_string],
'font.stretch': ['normal', validate_string],
'font.weight': ['normal', validate_string],
'font.weight': ['normal', validate_fontweight],
'font.size': [10, validate_float], # Base font size in points
'font.serif': [['DejaVu Serif', 'Bitstream Vera Serif',
'Computer Modern Roman',
Expand Down Expand Up @@ -1190,7 +1203,7 @@ def _validate_linestyle(ls):

'axes.titlesize': ['large', validate_fontsize], # fontsize of the
# axes title
'axes.titleweight': ['normal', validate_string], # font weight of axes title
'axes.titleweight': ['normal', validate_fontweight], # font weight of axes title
'axes.titlepad': [6.0, validate_float], # pad from axes top to title in points
'axes.grid': [False, validate_bool], # display grid or not
'axes.grid.which': ['major', validate_axis_locator], # set whether the gid are by
Expand All @@ -1202,7 +1215,7 @@ def _validate_linestyle(ls):
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
# x any y labels
'axes.labelpad': [4.0, validate_float], # space between label and axis
'axes.labelweight': ['normal', validate_string], # fontsize of the x any y labels
'axes.labelweight': ['normal', validate_fontweight], # fontsize of the x any y labels
'axes.labelcolor': ['black', validate_color], # color of axis label
'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
# use scientific notation if log10
Expand Down Expand Up @@ -1340,7 +1353,7 @@ def _validate_linestyle(ls):
## figure props
# figure title
'figure.titlesize': ['large', validate_fontsize],
'figure.titleweight': ['normal', validate_string],
'figure.titleweight': ['normal', validate_fontweight],

# figure size in inches: width by height
'figure.figsize': [[6.4, 4.8], validate_nseq_float(2)],
Expand Down
Loading
31CC
0