Skip to content

Commit e22defa

Browse files
authored
Merge branch 'matplotlib:main' into polar-errcaps
2 parents ed5d5ac + ecab6de commit e22defa

File tree

12 files changed

+234
-184
lines changed

12 files changed

+234
-184
lines changed

.github/workflows/cibuildwheel.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jobs:
3535
MACOSX_DEPLOYMENT_TARGET: "10.12"
3636
strategy:
3737
matrix:
38-
os: [ubuntu-18.04, windows-latest, macos-10.15]
38+
os: [ubuntu-20.04, windows-latest, macos-10.15]
3939
cibw_archs: ["auto"]
4040
include:
41-
- os: ubuntu-18.04
41+
- os: ubuntu-20.04
4242
cibw_archs: "aarch64"
4343

4444
steps:

.github/workflows/tests.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ jobs:
3333
matrix:
3434
include:
3535
- name-suffix: "(Minimum Versions)"
36-
os: ubuntu-18.04
36+
os: ubuntu-20.04
3737
python-version: 3.8
3838
extra-requirements: '-c requirements/testing/minver.txt'
3939
pyqt5-ver: '==5.11.2 sip==5.0.0' # oldest versions with a Py3.8 wheel.
4040
delete-font-cache: true
41-
- os: ubuntu-18.04
41+
- os: ubuntu-20.04
4242
python-version: 3.8
4343
extra-requirements: '-r requirements/testing/extra.txt'
4444
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
@@ -192,7 +192,6 @@ jobs:
192192
echo 'PySide2 is available' ||
193193
echo 'PySide2 is not available'
194194
fi
195-
# Qt6 crashes on Github's ubuntu 18.04 runner.
196195
if [[ "${{ matrix.os }}" = ubuntu-20.04 ]]; then
197196
python -mpip install --upgrade pyqt6 &&
198197
python -c 'import PyQt6.QtCore' &&

doc/devel/development_setup.rst

+37-11
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,33 @@
44
Setting up Matplotlib for development
55
=====================================
66

7+
Retrieving the latest version of the code
8+
=========================================
9+
10+
Matplotlib is hosted at https://github.com/matplotlib/matplotlib.git.
11+
12+
You can retrieve the latest sources with the command (see
13+
:ref:`set-up-fork` for more details)::
14+
15+
git clone https://github.com/matplotlib/matplotlib.git
16+
17+
This will place the sources in a directory :file:`matplotlib` below your
18+
current working directory.
19+
20+
If you have the proper privileges, you can use ``git@`` instead of
21+
``https://``, which works through the ssh protocol and might be easier to use
22+
if you are using 2-factor authentication.
23+
724
.. _dev-environment:
825

926
Creating a dedicated environment
1027
================================
1128
You should set up a dedicated environment to decouple your Matplotlib
1229
development from other Python and Matplotlib installations on your system.
30+
31+
Using virtual environments
32+
--------------------------
33+
1334
Here we use python's virtual environment `venv`_, but you may also use others
1435
such as conda.
1536

@@ -28,22 +49,27 @@ and activated with one of the following::
2849
Whenever you plan to work on Matplotlib, remember to activate the development
2950
environment in your shell.
3051

31-
Retrieving the latest version of the code
32-
=========================================
52+
Conda dev environment
53+
---------------------
54+
After you have cloned the repo change into the matplotlib directory.
3355

34-
Matplotlib is hosted at https://github.com/matplotlib/matplotlib.git.
56+
A new conda environment can be set-up with::
3557

36-
You can retrieve the latest sources with the command (see
37-
:ref:`set-up-fork` for more details)::
58+
conda env create -f environment.yml
3859

39-
git clone https://github.com/matplotlib/matplotlib.git
60+
Note that if you have mamba installed you can replace conda with mamba in
61+
the above command.
4062

41-
This will place the sources in a directory :file:`matplotlib` below your
42-
current working directory.
63+
To activate your environment::
4364

44-
If you have the proper privileges, you can use ``git@`` instead of
45-
``https://``, which works through the ssh protocol and might be easier to use
46-
if you are using 2-factor authentication.
65+
conda activate mpl-dev
66+
67+
Finish the install by the following command::
68+
69+
pip install -e .
70+
71+
Whenever you plan to work on Matplotlib, remember to ``conda activate mpl-dev``
72+
in your shell.
4773

4874
Installing Matplotlib in editable mode
4975
======================================

lib/matplotlib/colorbar.py

+39-89
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"""
1313

1414
import logging
15-
import textwrap
1615

1716
import numpy as np
1817

@@ -28,7 +27,8 @@
2827

2928
_log = logging.getLogger(__name__)
3029

31-
_make_axes_kw_doc = """
30+
_docstring.interpd.update(
31+
_make_axes_kw_doc="""
3232
location : None or {'left', 'right', 'top', 'bottom'}
3333
The location, relative to the parent axes, where the colorbar axes
3434
is created. It also determines the *orientation* of the colorbar
@@ -61,10 +61,8 @@
6161
panchor : (float, float), or *False*, optional
6262
The anchor point of the colorbar parent axes. If *False*, the parent
6363
axes' anchor will be unchanged.
64-
Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.
65-
"""
66-
67-
_colormap_kw_doc = """
64+
Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.""",
65+
_colormap_kw_doc="""
6866
extend : {'neither', 'both', 'min', 'max'}
6967
Make pointed end(s) for out-of-range values (unless 'neither'). These are
7068
set for a given colormap using the colormap set_under and set_over methods.
@@ -114,76 +112,7 @@
114112
each region delimited by adjacent entries in *boundaries*, the color mapped
115113
to the corresponding value in values will be used.
116114
Normally only useful for indexed colors (i.e. ``norm=NoNorm()``) or other
117-
unusual circumstances.
118-
"""
119-
120-
_docstring.interpd.update(colorbar_doc="""
121-
Add a colorbar to a plot.
122-
123-
Parameters
124-
----------
125-
mappable
126-
The `matplotlib.cm.ScalarMappable` (i.e., `~matplotlib.image.AxesImage`,
127-
`~matplotlib.contour.ContourSet`, etc.) described by this colorbar.
128-
This argument is mandatory for the `.Figure.colorbar` method but optional
129-
for the `.pyplot.colorbar` function, which sets the default to the current
130-
image.
131-
132-
Note that one can create a `.ScalarMappable` "on-the-fly" to generate
133-
colorbars not attached to a previously drawn artist, e.g. ::
134-
135-
fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax)
136-
137-
cax : `~matplotlib.axes.Axes`, optional
138-
Axes into which the colorbar will be drawn.
139-
140-
ax : `~matplotlib.axes.Axes`, list of Axes, optional
141-
One or more parent axes from which space for a new colorbar axes will be
142-
stolen, if *cax* is None. This has no effect if *cax* is set.
143-
144-
use_gridspec : bool, optional
145-
If *cax* is ``None``, a new *cax* is created as an instance of Axes. If
146-
*ax* is an instance of Subplot and *use_gridspec* is ``True``, *cax* is
147-
created as an instance of Subplot using the :mod:`.gridspec` module.
148-
149-
Returns
150-
-------
151-
colorbar : `~matplotlib.colorbar.Colorbar`
152-
153-
Notes
154-
-----
155-
Additional keyword arguments are of two kinds:
156-
157-
axes properties:
158-
%s
159-
colorbar properties:
160-
%s
161-
162-
If *mappable* is a `~.contour.ContourSet`, its *extend* kwarg is included
163-
automatically.
164-
165-
The *shrink* kwarg provides a simple way to scale the colorbar with respect
166-
to the axes. Note that if *cax* is specified, it determines the size of the
167-
colorbar and *shrink* and *aspect* kwargs are ignored.
168-
169-
For more precise control, you can manually specify the positions of
170-
the axes objects in which the mappable and the colorbar are drawn. In
171-
this case, do not use any of the axes properties kwargs.
172-
173-
It is known that some vector graphics viewers (svg and pdf) renders white gaps
174-
between segments of the colorbar. This is due to bugs in the viewers, not
175-
Matplotlib. As a workaround, the colorbar can be rendered with overlapping
176-
segments::
177-
178-
cbar = colorbar()
179-
cbar.solids.set_edgecolor("face")
180-
draw()
181-
182-
However this has negative consequences in other circumstances, e.g. with
183-
semi-transparent images (alpha < 1) and colorbar extensions; therefore, this
184-
workaround is not used by default (see issue #1188).
185-
""" % (textwrap.indent(_make_axes_kw_doc, " "),
186-
textwrap.indent(_colormap_kw_doc, " ")))
115+
unusual circumstances.""")
187116

188117

189118
def _set_ticks_on_axis_warn(*args, **kwargs):
@@ -267,7 +196,7 @@ def get_subplotspec(self):
267196
return ss()
268197

269198

270-
@_docstring.Substitution(_colormap_kw_doc)
199+
@_docstring.interpd
271200
class Colorbar:
272201
r"""
273202
Draw a colorbar in an existing axes.
@@ -327,7 +256,7 @@ class Colorbar:
327256
drawedges : bool
328257
329258
filled : bool
330-
%s
259+
%(_colormap_kw_doc)s
331260
"""
332261

333262
n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize
@@ -434,7 +363,8 @@ def __init__(self, ax, mappable=None, *, cmap=None,
434363
self.dividers = collections.LineCollection(
435364
[],
436365
colors=[mpl.rcParams['axes.edgecolor']],
437-
linewidths=[0.5 * mpl.rcParams['axes.linewidth']])
366+
linewidths=[0.5 * mpl.rcParams['axes.linewidth']],
367+
clip_on=False)
438368
self.ax.add_collection(self.dividers)
439369

440370
self._locator = None
@@ -650,12 +580,31 @@ def _add_solids(self, X, Y, C):
650580
if not self.drawedges:
651581
if len(self._y) >= self.n_rasterize:
652582
self.solids.set_rasterized(True)
653-
if self.drawedges:
654-
start_idx = 0 if self._extend_lower() else 1
655-
end_idx = len(X) if self._extend_upper() else -1
656-
self.dividers.set_segments(np.dstack([X, Y])[start_idx:end_idx])
657-
else:
583+
self._update_dividers()
584+
585+
def _update_dividers(self):
586+
if not self.drawedges:
658587
self.dividers.set_segments([])
588+
return
589+
# Place all *internal* dividers.
590+
if self.orientation == 'vertical':
591+
lims = self.ax.get_ylim()
592+
bounds = (lims[0] < self._y) & (self._y < lims[1])
593+
else:
594+
lims = self.ax.get_xlim()
595+
bounds = (lims[0] < self._y) & (self._y < lims[1])
596+
y = self._y[bounds]
597+
# And then add outer dividers if extensions are on.
598+
if self._extend_lower():
599+
y = np.insert(y, 0, lims[0])
600+
if self._extend_upper():
601+
y = np.append(y, lims[1])
602+
X, Y = np.meshgrid([0, 1], y)
603+
if self.orientation == 'vertical':
604+
segments = np.dstack([X, Y])
605+
else:
606+
segments = np.dstack([Y, X])
607+
self.dividers.set_segments(segments)
659608

660609
def _add_solids_patches(self, X, Y, C, mappable):
661610
hatches = mappable.hatches * len(C) # Have enough hatches.
@@ -760,7 +709,8 @@ def _do_extends(self, ax=None):
760709
zorder=np.nextafter(self.ax.patch.zorder, -np.inf))
761710
self.ax.add_patch(patch)
762711
self._extend_patches.append(patch)
763-
return
712+
713+
self._update_dividers()
764714

765715
def add_lines(self, *args, **kwargs):
766716
"""
@@ -1404,7 +1354,7 @@ def _normalize_location_orientation(location, orientation):
14041354
return loc_settings
14051355

14061356

1407-
@_docstring.Substitution(_make_axes_kw_doc)
1357+
@_docstring.interpd
14081358
def make_axes(parents, location=None, orientation=None, fraction=0.15,
14091359
shrink=1.0, aspect=20, **kwargs):
14101360
"""
@@ -1417,7 +1367,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14171367
----------
14181368
parents : `~.axes.Axes` or list of `~.axes.Axes`
14191369
The Axes to use as parents for placing the colorbar.
1420-
%s
1370+
%(_make_axes_kw_doc)s
14211371
14221372
Returns
14231373
-------
@@ -1506,7 +1456,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
15061456
return cax, kwargs
15071457

15081458

1509-
@_docstring.Substitution(_make_axes_kw_doc)
1459+
@_docstring.interpd
15101460
def make_axes_gridspec(parent, *, location=None, orientation=None,
15111461
fraction=0.15, shrink=1.0, aspect=20, **kwargs):
15121462
"""
@@ -1532,7 +1482,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
15321482
----------
15331483
parent : `~.axes.Axes`
15341484
The Axes to use as parent for placing the colorbar.
1535-
%s
1485+
%(_make_axes_kw_doc)s
15361486
15371487
Returns
15381488
-------

0 commit comments

Comments
 (0)