8000 Merge branch 'main' of https://github.com/0taj/matplotlib into test_e… · matplotlib/matplotlib@8d79d0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d79d0c

Browse files
committed
Merge branch 'main' of https://github.com/0taj/matplotlib into test_errorbar
2 parents 0d0f3c2 + b86e331 commit 8d79d0c

File tree

20 files changed

+405
-133
lines changed

20 files changed

+405
-133
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*loc* parameter of ``Cell`` doesn't accept ``None`` anymore
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The default value of the *loc* parameter has been changed from ``None`` to ``right``,
5+
which already was the default location. The behavior of `.Cell` didn't change when
6+
called without an explicit *loc* parameter.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``passthru_pt``
2+
~~~~~~~~~~~~~~~
3+
4+
This attribute of ``AxisArtistHelper``\s has been removed.

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ def _check_dependencies():
207207
'scipy': ('https://docs.scipy.org/doc/scipy/', None),
208208
'tornado': ('https://www.tornadoweb.org/en/stable/', None),
209209
'xarray': ('https://docs.xarray.dev/en/stable/', None),
210+
'meson-python': ('https://meson-python.readthedocs.io/en/stable/', None)
210211
}
211212

212213

doc/devel/dependencies.rst

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
.. _dependencies:
22

3-
============
3+
************
44
Dependencies
5-
============
5+
************
6+
7+
.. _runtime_dependencies:
68

79
Runtime dependencies
810
====================
911

1012

11-
Mandatory dependencies
12-
----------------------
13+
Required
14+
--------
1315

1416
When installing through a package manager like ``pip`` or ``conda``, the
1517
mandatory dependencies are automatically installed. This list is mainly for
@@ -31,8 +33,8 @@ reference.
3133

3234
.. _optional_dependencies:
3335

34-
Optional dependencies
35-
---------------------
36+
Optional
37+
--------
3638

3739
The following packages and tools are not required but extend the capabilities
3840
of Matplotlib.
@@ -106,10 +108,14 @@ Additionally, Matplotlib depends on:
106108
.. _FreeType: https://www.freetype.org/
107109
.. _Qhull: http://www.qhull.org/
108110

109-
By default, Matplotlib downloads and builds its own copies of FreeType (this is
110-
necessary to run the test suite, because different versions of FreeType
111-
rasterize characters differently) and of Qhull. As an exception, Matplotlib
112-
defaults to the system version of FreeType on AIX.
111+
112+
Download during install
113+
^^^^^^^^^^^^^^^^^^^^^^^
114+
115+
By default, Matplotlib downloads and builds its own copies of Qhull and FreeType.
116+
The vendored version of FreeType is necessary to run the test suite, because
117+
different versions of FreeType rasterize characters differently.
118+
113119

114120
Use system libraries
115121
^^^^^^^^^^^^^^^^^^^^
@@ -176,9 +182,8 @@ remember to clear your artifacts before re-building::
176182

177183
git clean -xfd
178184

179-
180-
Manual Download
181-
^^^^^^^^^^^^^^^
185+
From source files
186+
^^^^^^^^^^^^^^^^^
182187

183188
If the automatic download does not work (for example, on air-gapped systems) it is
184189
preferable to instead use system libraries. However you can manually download the
@@ -202,19 +207,23 @@ In all cases the required version of pip is embedded in the CPython source.
202207

203208
.. _development-dependencies:
204209

205-
Dependencies for building Matplotlib
206-
====================================
210+
Build dependencies
211+
==================
212+
207213

208214
.. _setup-dependencies:
209215

210-
Setup dependencies
211-
------------------
216+
Python
217+
------
218+
219+
By default, ``pip`` will build packages using build isolation, meaning that these
220+
build dependencies are temporally installed by pip for the duration of the
221+
Matplotlib build process. However, build isolation is disabled when :ref:`installing Matplotlib for development <development-install>`;
222+
therefore we recommend using one of our :ref:`virtual environment configurations <dev-environment>` to
223+
create a development environment in which these packages are automatically installed.
212224

213-
By default, ``pip`` will build packages using build isolation, and the following
214-
dependencies will be automatically installed in the isolated environment to build
215-
Matplotlib. However, for development, you may wish to make an editable install, which
216-
will require disabling build isolation, so these build dependencies should be installed
217-
in your target environment manually:
225+
If you are developing Matplotlib and unable to use our environment configurations,
226+
then you must manually install the following packages into your development environment:
218227

219228
- `meson-python <https://meson-python.readthedocs.io/>`_ (>= 0.13.1).
220229
- `ninja <https://ninja-build.org/>`_ (>= 1.8.2). This may be available in your package
@@ -230,11 +239,13 @@ in your target environment manually:
230239

231240
.. _compile-dependencies:
232241

233-
C++ compiler
234-
------------
242+
Compiled extensions
243+
-------------------
235244

236245
Matplotlib requires a C++ compiler that supports C++17, and each platform has a
237246
development environment that must be installed before a compiler can be installed.
247+
You may also need to install headers for various libraries used in the compiled extension
248+
source files.
238249

239250
.. tab-set::
240251

@@ -261,6 +272,8 @@ development environment that must be installed before a compiler can be installe
261272

262273
Alternatively, you can install a Linux-like environment such as `CygWin <https://www.cygwin.com/>`_
263274
or `Windows Subsystem for Linux <https://learn.microsoft.com/en-us/windows/wsl/install>`_.
275+
If using `MinGW-64 <https://www.mingw-w64.org/>`_, we require **v6** of the
276+
```Mingw-w64-x86_64-headers``.
264277

265278

266279
We highly recommend that you install a compiler using your platform tool, i.e.,
@@ -294,16 +307,19 @@ Xcode, VS Code or Linux package manager. Choose **one** compiler from this list:
294307

295308
.. _test-dependencies:
296309

297-
Dependencies for testing Matplotlib
298-
===================================
310+
Test dependencies
311+
=================
312+
299313
This section lists the additional software required for
300314
:ref:`running the tests <testing>`.
301315

302-
Required:
316+
Required
317+
--------
303318

304319
- pytest_ (>= 7.0.0)
305320

306-
Optional:
321+
Optional
322+
--------
307323

308324
In addition to all of the optional dependencies on the main library, for
309325
testing the following will be used if they are installed.
@@ -357,11 +373,12 @@ them will be skipped by pytest.
357373

358374
.. _doc-dependencies:
359375

360-
Dependencies for building Matplotlib's documentation
361-
====================================================
376+
Documentation dependencies
377+
==========================
378+
379+
Python
380+
------
362381

363-
Python packages
364-
---------------
365382
The additional Python packages required to build the
366383
:ref:`documentation <documenting-matplotlib>` are listed in
367384
:file:`doc-requirements.txt` and can be installed using ::
@@ -373,13 +390,22 @@ The content of :file:`doc-requirements.txt` is also shown below:
373390
.. include:: ../../requirements/doc/doc-requirements.txt
374391
:literal:
375392

376-
Additional external dependencies
377-
--------------------------------
378-
Required:
379393

394+
External tools
395+
--------------
396+
397+
The documentation requires LaTeX and Graphviz. These are not
398+
Python packages and must be installed separately. The documentation can be
399+
built without Inkscape and optipng, but the build process will raise various
400+
warnings. If the build process warns that you are missing fonts, make sure
401+
your LaTeX distribution bundles cm-super or install it separately.
402+
403+
Required
404+
^^^^^^^^
405+
406+
* `Graphviz <http://www.graphviz.org/download>`_
380407
* a minimal working LaTeX distribution, e.g., `TeX Live <https://www.tug.org/texlive/>`_ or
381408
`MikTeX <https://miktex.org/>`_
382-
* `Graphviz <http://www.graphviz.org/download>`_
383409
* the following LaTeX packages (if your OS bundles TeX Live, the
384410
"complete" version of the installer, e.g. "texlive-full" or "texlive-all",
385411
will often automatically include these packages):
@@ -388,18 +414,11 @@ Required:
388414
* `dvipng <https://ctan.org/pkg/dvipng>`_
389415
* `underscore <https://ctan.org/pkg/underscore>`_
390416

391-
Optional, but recommended:
417+
Optional
418+
^^^^^^^^
392419

393420
* `Inkscape <https://inkscape.org>`_
394421
* `optipng <http://optipng.sourceforge.net>`_
395422
* the font "Humor Sans" (aka the "XKCD" font), or the free alternative
396423
`Comic Neue <http://comicneue.com/>`_
397424
* the font "Times New Roman"
398-
399-
.. note::
400-
401-
The documentation will not build without LaTeX and Graphviz. These are not
402-
Python packages and must be installed separately. The documentation can be
403-
built without Inkscape and optipng, but the build process will raise various
404-
warnings. If the build process warns that you are missing fonts, make sure
405-
your LaTeX distribution bundles cm-super or install it separately.

doc/devel/development_setup.rst

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ Most Python dependencies will be installed when :ref:`setting up the environment
154154
but non-Python dependencies like C++ compilers, LaTeX, and other system applications
155155
must be installed separately. For a full list, see :ref:`dependencies`.
156156

157+
.. _development-install:
158+
157159
Install Matplotlib in editable mode
158160
===================================
159161

@@ -164,12 +166,25 @@ command ::
164166

165167
The 'editable/develop mode' builds everything and places links in your Python environment
166168
so that Python will be able to import Matplotlib from your development source directory.
167-
This allows you to import your modified version of Matplotlib without re-installing after
168-
every change. Note that before the merging of the `Meson port
169-
<https://github.com/matplotlib/matplotlib/pull/26621>`_, this is only true for ``*.py``
170-
files. If you change the C-extension source based on a commit before the change to the
171-
Meson build system (which might also happen if you change branches), you will have to
172-
re-run the above command.
169+
This allows you to import your modified version of Matplotlib without having to
170+
re-install after changing a ``.py`` or compiled extension file.
171+
172+
When working on a branch that does not have Meson enabled, meaning it does not
173+
have :ghpull:`26621` in its history (log), you will have to reinstall from source
174+
each time you change any compiled extension code.
175+
176+
Build options
177+
-------------
178+
If you are working heavily with files that need to be compiled, you may want to
179+
inspect the compilation log. This can be enabled by setting the environment
180+
variable :envvar:`MESONPY_EDITABLE_VERBOSE` or by setting the ``editable-verbose``
181+
config during installation ::
182+
183+
python -m pip install --no-build-isolation --config-settings=editable-verbose=true --editable .
184+
185+
For more information on installation and other configuration options, see the
186+
Meson Python :external+meson-python:ref:`editable installs guide <how-to-guides-editable-installs>`.
187+
173188

174189
Verify the Installation
175190
=======================

doc/devel/troubleshooting.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@ unlink this file. Multiple versions of Matplotlib can be linked to the same DLL,
4343
for example a development version installed in a development conda environment
4444
and a stable version running in a Jupyter notebook. To resolve this error, fully
4545
close all running instances of Matplotlib.
46+
47+
Windows compilation errors
48+
==========================
49+
If the compiled extensions are not building on Windows due to errors in linking to
50+
Windows' header files, for example ``../../src/_tkagg.cpp:133:10: error: 'WM_DPICHANGED' was not declared in this scope``,
51+
you should check which compiler Meson is using:
52+
53+
.. code-block:: bat
54+
55+
Build type: native build
56+
Project name: matplotlib
57+
Project version: 3.9.0.dev0
58+
C compiler for the host machine: cc (gcc 7.2.0 "cc (Rev1, Built by MSYS2 project) 7.2.0")
59+
C linker for the host machine: cc ld.bfd 2.29.1
60+
C++ compiler for the host machine: c++ (gcc 7.2.0 "c++ (Rev1, Built by MSYS2 project) 7.2.0")
61+
C++ linker for the host machine: c++ ld.bfd 2.29.1
62+
63+
Our :ref:`dependencies <dependencies>` documentation lists the minimum header
64+
version if you intended to use ``MSYS2``. If you intended to use ``MSVC`` then
65+
you may need to force Meson to :external+meson-python:ref:`use MSVC <vsenv-example>`.

doc/users/installing/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ precompiled wheel for your OS and Python.
3131

3232
For support of other GUI frameworks, LaTeX rendering, saving
3333
animations and a larger selection of file formats, you can
34-
install :ref:`optional_dependencies`.
34+
install :ref:`optional dependencies <optional_dependencies>`.
3535

3636

3737
Third-party distributions

galleries/examples/color/named_colors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ def plot_colortable(colors, *, ncols=4, sort_colors=True):
101101
# -----------
102102
# XKCD Colors
103103
# -----------
104-
# XKCD colors are supported, but they produce a large figure, so we skip them
105-
# for now. You can use the following code if desired::
104+
# Matplotlib supports colors from the
105+
# `xkcd color survey <https://xkcd.com/color/rgb/>`_, e.g. ``"xkcd:sky blue"``. Since
106+
# this contains almost 1000 colors, a figure of this would be very large and is thus
107+
# omitted here. You can use the following code to generate the overview yourself ::
106108
#
107109
# xkcd_fig = plot_colortable(mcolors.XKCD_COLORS)
108110
# xkcd_fig.savefig("XKCD_Colors.png")
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
===========
3+
Bihistogram
4+
===========
5+
6+
How to plot a bihistogram with Matplotlib.
7+
"""
8+
9+
import matplotlib.pyplot as plt
10+
import numpy as np
11+
12+
# Create a random number generator with a fixed seed for reproducibility
13+
rng = np.random.default_rng(19680801)
14+
15+
# %%
16+
# Generate data and plot a bihistogram
17+
# ------------------------------------
18+
#
19+
# To generate a bihistogram we need two datasets (each being a vector of numbers).
20+
# We will plot both histograms using plt.hist() and set the weights of the second
21+
# one to be negative. We'll generate data below and plot the bihistogram.
22+
23+
N_points = 10_000
24+
25+
# Generate two normal distributions
26+
dataset1 = np.random.normal(0, 1, size=N_points)
27+
dataset2 = np.random.normal(1, 2, size=N_points)
28+
29+
# Use a constant bin width to make the two histograms easier to compare visually
30+
bin_width = 0.25
31+
bins = np.arange(np.min([dataset1, dataset2]),
32+
np.max([dataset1, dataset2]) + bin_width, bin_width)
33+
34+
fig, ax = plt.subplots()
35+
36+
# Plot the first histogram
37+
ax.hist(dataset1, bins=bins, label="Dataset 1")
38+
39+
# Plot the second histogram
40+
# (notice the negative weights, which flip the histogram upside down)
41+
ax.hist(dataset2, weights=-np.ones_like(dataset2), bins=bins, label="Dataset 2")
42+
ax.axhline(0, color="k")
43+
ax.legend()
44+
45+
plt.show()

lib/matplotlib/backends/qt_compat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _exec(obj):
163163

164164

165165
@contextlib.contextmanager
166-
def _maybe_allow_interrupt(qapp):
166+
def _maybe_allow_interrupt(qapp_or_eventloop):
167167
"""
168168
This manager allows to terminate a plot by sending a SIGINT. It is
169169
necessary because the running Qt backend prevents Python interpreter to
@@ -215,7 +215,9 @@ def _may_clear_sock(*args):
215215
def handle(*args):
216216
nonlocal handler_args
217217
handler_args = args
218-
qapp.quit()
218+
if hasattr(qapp_or_eventloop, 'closeAllWindows'):
219+
qapp_or_eventloop.closeAllWindows()
220+
qapp_or_eventloop.quit()
219221

220222
signal.signal(signal.SIGINT, handle)
221223
try:

0 commit comments

Comments
 (0)
0