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

Skip to content

Commit 5881a90

Browse files
authored
Merge branch 'matplotlib:main' into axes-contourf-unit-test-for-issue-26864
2 parents 677a406 + 4aa7efe commit 5881a90

File tree

7 files changed

+101
-26
lines changed

7 files changed

+101
-26
lines changed

.github/workflows/nightlies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
ls -l dist/
6060
6161
- name: Upload wheels to Anaconda Cloud as nightlies
62-
uses: scientific-python/upload-nightly-action@8f0394fd2aa0c85d7364a9958652e8994e06b23c # 0.1.0
62+
uses: scientific-python/upload-nightly-action@5fb764c5bce1ac2297084c0f7161b1919f17c74f # 0.2.0
6363
with:
6464
artifacts_path: dist
6565
anaconda_nightly_upload_token: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }}

doc/devel/document.rst

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ It is useful to strive for consistency in the Matplotlib documentation. Here
142142
are some formatting and style conventions that are used.
143143

144144
Section formatting
145-
~~~~~~~~~~~~~~~~~~
145+
^^^^^^^^^^^^^^^^^^
146146

147147
Use `sentence case <https://apastyle.apa.org/style-grammar-guidelines/capitalization/sentence-case>`__
148148
``Upper lower`` for section titles, e.g., ``Possible hangups`` rather than
@@ -163,8 +163,25 @@ for section markup characters, i.e.:
163163

164164
This may not yet be applied consistently in existing docs.
165165

166+
Table formatting
167+
^^^^^^^^^^^^^^^^
168+
Given the size of the table and length of each entry, use:
169+
170+
+-------------+-------------------------------+--------------------+
171+
| | small table | large table |
172+
+-------------+-------------------------------+--------------------+
173+
| short entry | `simple or grid table <sg>`_ | `grid table <sg>`_ |
174+
+-------------+-------------------------------+--------------------+
175+
| long entry | `list table <lt>`_ | `csv table <csv>`_ |
176+
+-------------+-------------------------------+--------------------+
177+
178+
For more information, see `rst tables <https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#tables>`_.
179+
.. _sg: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#tables
180+
.. _lt: https://docutils.sourceforge.io/docs/ref/rst/directives.html#list-table
181+
.. _csv: https://docutils.sourceforge.io/docs/ref/rst/directives.html#toc-entry-22
182+
166183
Function arguments
167-
~~~~~~~~~~~~~~~~~~
184+
^^^^^^^^^^^^^^^^^^
168185

169186
Function arguments and keywords within docstrings should be referred to using
170187
the ``*emphasis*`` role. This will keep Matplotlib's documentation consistent
@@ -445,7 +462,8 @@ and the Sphinx_ documentation. Some Matplotlib-specific formatting conventions
445462
to keep in mind:
446463

447464
Quote positions
448-
~~~~~~~~~~~~~~~
465+
^^^^^^^^^^^^^^^
466+
449467
The quotes for single line docstrings are on the same line (pydocstyle D200)::
450468

451469
def get_linewidth(self):
@@ -461,7 +479,8 @@ The quotes for multi-line docstrings are on separate lines (pydocstyle D213)::
461479
"""
462480

463481
Function arguments
464-
~~~~~~~~~~~~~~~~~~
482+
^^^^^^^^^^^^^^^^^^
483+
465484
Function arguments and keywords within docstrings should be referred to
466485
using the ``*emphasis*`` role. This will keep Matplotlib's documentation
467486
consistent with Python's documentation:
@@ -478,7 +497,8 @@ Do not use the ```default role``` or the ````literal```` role:
478497
479498
480499
Quotes for strings
481-
~~~~~~~~~~~~~~~~~~
500+
^^^^^^^^^^^^^^^^^^
501+
482502
Matplotlib does not have a convention whether to use single-quotes or
483503
double-quotes. There is a mixture of both in the current code.
484504

@@ -495,7 +515,8 @@ slightly improve the rendered docs, they are cumbersome to type and difficult
495515
to read in plain-text docs.
496516

497517
Parameter type descriptions
498-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
518+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
519+
499520
The main goal for parameter type descriptions is to be readable and
500521
understandable by humans. If the possible types are too complex use a
501522
simplification for the type description and explain the type more
@@ -534,7 +555,8 @@ Non-numeric homogeneous sequences are described as lists, e.g.::
534555
list of `.Artist`
535556

536557
Reference types
537-
~~~~~~~~~~~~~~~
558+
^^^^^^^^^^^^^^^
559+
538560
Generally, the rules from referring-to-other-code_ apply. More specifically:
539561

540562
Use full references ```~matplotlib.colors.Normalize``` with an
@@ -550,7 +572,8 @@ Use abbreviated links ```.Normalize``` in the text.
550572
A `.Normalize` instance is used to scale luminance data to 0, 1.
551573
552574
Default values
553-
~~~~~~~~~~~~~~
575+
^^^^^^^^^^^^^^
576+
554577
As opposed to the numpydoc guide, parameters need not be marked as
555578
*optional* if they have a simple default:
556579

@@ -592,7 +615,8 @@ effect.
592615
593616
594617
``See also`` sections
595-
~~~~~~~~~~~~~~~~~~~~~
618+
^^^^^^^^^^^^^^^^^^^^^
619+
596620
Sphinx automatically links code elements in the definition blocks of ``See
597621
also`` sections. No need to use backticks there::
598622

@@ -602,7 +626,8 @@ also`` sections. No need to use backticks there::
602626
axhline : horizontal line across the Axes
603627

604628
Wrap parameter lists
605-
~~~~~~~~~~~~~~~~~~~~
629+
^^^^^^^^^^^^^^^^^^^^
630+
606631
Long parameter lists should be wrapped using a ``\`` for continuation and
607632
starting on the new line without any indent (no indent because pydoc will
608633
parse the docstring and strip the line continuation so that indent would
@@ -627,7 +652,8 @@ Alternatively, you can describe the valid parameter values in a dedicated
627652
section of the docstring.
628653

629654
rcParams
630-
~~~~~~~~
655+
^^^^^^^^
656+
631657
rcParams can be referenced with the custom ``:rc:`` role:
632658
:literal:`:rc:\`foo\`` yields ``rcParams["foo"] = 'default'``, which is a link
633659
to the :file:`matplotlibrc` file description.

galleries/users_explain/toolkits/axisartist.rst

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -341,18 +341,37 @@ On the other hand, there is a concept of "axis_direction". This is a
341341
default setting of above properties for each, "bottom", "left", "top",
342342
and "right" axis.
343343

344-
========== ========== ========= ========== ========= ==========
345-
label type parameter left bottom right top
346-
========== ========== ========= ========== ========= ==========
347-
axislabel direction '-' '+' '+' '-'
348-
axislabel rotation 180 0 0 180
349-
axislabel va center top center bottom
350-
axislabel ha right center right center
351-
ticklabel direction '-' '+' '+' '-'
352-
ticklabel rotation 90 0 -90 180
353-
ticklabel ha right center right center
354-
ticklabel va center baseline center baseline
355-
========== ========== ========= ========== ========= ==========
344+
.. table:: ``axislabel`` property defaults
345+
346+
+---------------------+-----------------+----------------+----------------------+--------------------+
347+
| reference direction | label direction | label rotation | horizontal alignment | vertical alignment |
348+
+=====================+=================+================+======================+====================+
349+
| left | '-' | 180 | right | center |
350+
+---------------------+-----------------+----------------+----------------------+--------------------+
351+
| bottom | '+' | 0 | center | top |
352+
+---------------------+-----------------+----------------+----------------------+--------------------+
353+
| right | '+' | 0 | right | center |
354+
+---------------------+-----------------+----------------+----------------------+--------------------+
355+
| top | '-' | 180 | center | bottom |
356+
+---------------------+-----------------+----------------+----------------------+--------------------+
357+
358+
359+
360+
.. table:: ``ticklabel`` property defaults
361+
362+
+---------------------+-----------------+----------------+----------------------+--------------------+
363+
| reference direction | label direction | label rotation | horizontal alignment | vertical alignment |
364+
+=====================+=================+================+======================+====================+
365+
| left | '-' | 90 | right | center |
366+
+---------------------+-----------------+----------------+----------------------+--------------------+
367+
| bottom | '+' | 0 | center | baseline |
368+
+---------------------+-----------------+----------------+----------------------+--------------------+
369+
| right | '+' | -90 | right | center |
370+
+---------------------+-----------------+----------------+----------------------+--------------------+
371+
| top | '-' | 180 | center | baseline |
372+
+---------------------+-----------------+----------------+----------------------+--------------------+
373+
374+
356375

357376
And, 'set_axis_direction("top")' means to adjust the text rotation
358377
etc, for settings suitable for "top" axis. The concept of axis

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
404404
try:
405405
self._formatter = ticker.FormatStrFormatter(format)
406406
_ = self._formatter(0)
407-
except TypeError:
407+
except (TypeError, ValueError):
408408
self._formatter = ticker.StrMethodFormatter(format)
409409
else:
410410
self._formatter = format # Assume it is a Formatter or None

lib/matplotlib/legend.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,12 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs):
13371337
_api.warn_external("You have mixed positional and keyword arguments, "
13381338
"some input may be discarded.")
13391339

1340+
if (hasattr(handles, "__len__") and
1341+
hasattr(labels, "__len__") and
1342+
len(handles) != len(labels)):
1343+
_api.warn_external(f"Mismatched number of handles and labels: "
1344+
f"len(handles) = {len(handles)} "
1345+
f"len(labels) = {len(labels)}")
13401346
# if got both handles and labels as kwargs, make same length
13411347
if handles and labels:
13421348
handles, labels = zip(*zip(handles, labels))

lib/matplotlib/tests/test_colorbar.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
BoundaryNorm, LogNorm, PowerNorm, Normalize, NoNorm
1616
)
1717
from matplotlib.colorbar import Colorbar
18-
from matplotlib.ticker import FixedLocator, LogFormatter
18+
from matplotlib.ticker import FixedLocator, LogFormatter, StrMethodFormatter
1919
from matplotlib.testing.decorators import check_figures_equal
2020

2121

@@ -1230,3 +1230,9 @@ def test_colorbar_wrong_figure():
12301230
fig_tl.colorbar(im)
12311231
fig_tl.draw_without_rendering()
12321232
fig_cl.draw_without_rendering()
1233+
1234+
1235+
def test_colorbar_format_string_and_old():
1236+
plt.imshow([[0, 1]])
1237+
cb = plt.colorbar(format="{x}%")
1238+
assert isinstance(cb._formatter, StrMethodFormatter)

lib/matplotlib/tests/test_legend.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,3 +1357,21 @@ def test_loc_validation_string_value():
13571357
ax.legend(loc='upper center')
13581358
with pytest.raises(ValueError, match="'wrong' is not a valid value for"):
13591359
ax.legend(loc='wrong')
1360+
1361+
1362+
def test_legend_handle_label_mismatch():
1363+
pl1, = plt.plot(range(10))
1364+
pl2, = plt.plot(range(10))
1365+
with pytest.warns(UserWarning, match="number of handles and labels"):
1366+
legend = plt.legend(handles=[pl1, pl2], labels=["pl1", "pl2", "pl3"])
1367+
assert len(legend.legend_handles) == 2
1368+
assert len(legend.get_texts()) == 2
1369+
1370+
1371+
def test_legend_handle_label_mismatch_no_len():
1372+
pl1, = plt.plot(range(10))
1373+
pl2, = plt.plot(range(10))
1374+
legend = plt.legend(handles=iter([pl1, pl2]),
1375+
labels=iter(["pl1", "pl2", "pl3"]))
1376+
assert len(legend.legend_handles) == 2
1377+
assert len(legend.get_texts()) == 2

0 commit comments

Comments
 (0)