File: index.rst

package info (click to toggle)
matplotlib 3.10.1%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,340 kB
  • sloc: python: 147,118; cpp: 62,988; objc: 1,679; ansic: 1,426; javascript: 786; makefile: 92; sh: 53
file content (294 lines) | stat: -rw-r--r-- 10,093 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
.. redirect-from:: /users/installing
.. redirect-from:: /users/installing/index

************
Installation
************


Install an official release
===========================

Matplotlib releases are available as wheel packages for macOS, Windows and
Linux on `PyPI <https://pypi.org/project/matplotlib/>`_. Install it using
``pip``:

.. code-block:: sh

  python -m pip install -U pip
  python -m pip install -U matplotlib

If this command results in Matplotlib being compiled from source and
there's trouble with the compilation, you can add ``--prefer-binary`` to
select the newest version of Matplotlib for which there is a
precompiled wheel for your OS and Python.

.. note::

   The following backends work out of the box: Agg, ps, pdf, svg

   Python is typically shipped with tk bindings which are used by
   TkAgg.

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


Third-party distributions
=========================

Various third-parties provide Matplotlib for their environments.

Conda packages
--------------

Matplotlib is available both via the *anaconda main channel*

.. code-block:: sh

   conda install matplotlib

as well as via the *conda-forge community channel*

.. code-block:: sh

   conda install -c conda-forge matplotlib

Python distributions
--------------------

Matplotlib is part of major Python distributions:

- `Anaconda <https://www.anaconda.com/>`_

- `ActiveState ActivePython
  <https://www.activestate.com/products/python/downloads/>`_

- `WinPython <https://winpython.github.io/>`_

Linux package manager
---------------------

If you are using the Python version that comes with your Linux distribution,
you can install Matplotlib via your package manager, e.g.:

* Debian / Ubuntu: ``sudo apt-get install python3-matplotlib``
* Fedora: ``sudo dnf install python3-matplotlib``
* Red Hat: ``sudo yum install python3-matplotlib``
* Arch: ``sudo pacman -S python-matplotlib``

.. redirect-from:: /users/installing/installing_source

.. _install_from_source:

Install a nightly build
=======================

Matplotlib makes nightly development build wheels available on the
`scientific-python-nightly-wheels Anaconda Cloud organization
<https://anaconda.org/scientific-python-nightly-wheels>`_.
These wheels can be installed with ``pip`` by specifying
scientific-python-nightly-wheels as the package index to query:

.. code-block:: sh

  python -m pip install \
    --upgrade \
    --pre \
    --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
    --extra-index-url https://pypi.org/simple \
    matplotlib


Install from source
===================

.. admonition:: Installing for Development
  :class: important

  If you would like to contribute to Matplotlib or otherwise need to
  install the latest development code, please follow the instructions in
  :ref:`installing_for_devs`.

The following instructions are for installing from source for production use.
This is generally *not* recommended; please use prebuilt packages when possible.
Proceed with caution because these instructions may result in your
build producing unexpected behavior and/or causing local testing to fail.

Before trying to install Matplotlib, please install the :ref:`dependencies`.

To build from a tarball, download the latest *tar.gz* release
file from `the PyPI files page <https://pypi.org/project/matplotlib/>`_.

If you are building your own Matplotlib wheels (or sdists) on Windows, note
that any DLLs that you copy into the source tree will be packaged too.

Configure build and behavior defaults
=====================================

We provide a `meson.options`_ file containing options with which you can use to
customize the build process. For example, which default backend to use, whether some of
the optional libraries that Matplotlib ships with are installed, and so on. These
options will be particularly useful to those packaging Matplotlib.

.. _meson.options: https://github.com/matplotlib/matplotlib/blob/main/meson.options

Aspects of some behaviorial defaults of the library can be configured via:

.. toctree::
  :maxdepth: 2

  environment_variables_faq.rst

Default plotting appearance and behavior can be configured via the
:ref:`rcParams file <customizing-with-matplotlibrc-files>`


Dependencies
============

Mandatory dependencies should be installed automatically if you install Matplotlib using
a package manager such as ``pip`` or ``conda``; therefore this list is primarily for
reference and troubleshooting.

.. toctree::
  :maxdepth: 2

  dependencies


.. _installing-faq:

Frequently asked questions
===========================

Report a compilation problem
----------------------------

See :ref:`reporting-problems`.

Matplotlib compiled fine, but nothing shows up when I use it
------------------------------------------------------------

The first thing to try is a :ref:`clean install <clean-install>` and see if
that helps.  If not, the best way to test your install is by running a script,
rather than working interactively from a python shell or an integrated
development environment such as :program:`IDLE` which add additional
complexities. Open up a UNIX shell or a DOS command prompt and run, for
example::

   python -c "from pylab import *; set_loglevel('debug'); plot(); show()"

This will give you additional information about which backends Matplotlib is
loading, version information, and more. At this point you might want to make
sure you understand Matplotlib's :ref:`configuration <customizing>`
process, governed by the :file:`matplotlibrc` configuration file which contains
instructions within and the concept of the Matplotlib backend.

If you are still having trouble, see :ref:`reporting-problems`.

.. _clean-install:

How to completely remove Matplotlib
-----------------------------------

Occasionally, problems with Matplotlib can be solved with a clean
installation of the package.  In order to fully remove an installed Matplotlib:

1. Delete the caches from your :ref:`Matplotlib configuration directory
   <locating-matplotlib-config-dir>`.

2. Delete any Matplotlib directories or eggs from your :ref:`installation
   directory <locating-matplotlib-install>`.

macOS Notes
-----------

.. _which-python-for-macos:

Which python for macOS?
^^^^^^^^^^^^^^^^^^^^^^^

Apple ships macOS with its own Python, in ``/usr/bin/python``, and its own copy
of Matplotlib. Unfortunately, the way Apple currently installs its own copies
of NumPy, Scipy and Matplotlib means that these packages are difficult to
upgrade (see `system python packages`_).  For that reason we strongly suggest
that you install a fresh version of Python and use that as the basis for
installing libraries such as NumPy and Matplotlib.  One convenient way to
install Matplotlib with other useful Python software is to use the Anaconda_
Python scientific software collection, which includes Python itself and a
wide range of libraries; if you need a library that is not available from the
collection, you can install it yourself using standard methods such as *pip*.
See the Anaconda web page for installation support.

.. _system python packages:
    https://github.com/MacPython/wiki/wiki/Which-Python#system-python-and-extra-python-packages
.. _Anaconda: https://www.anaconda.com/

Other options for a fresh Python install are the standard installer from
`python.org <https://www.python.org/downloads/macos/>`_, or installing
Python using a general macOS package management system such as `homebrew
<https://brew.sh/>`_ or `macports <https://www.macports.org>`_.  Power users on
macOS will likely want one of homebrew or macports on their system to install
open source software packages, but it is perfectly possible to use these
systems with another source for your Python binary, such as Anaconda
or Python.org Python.

.. _install_macos_binaries:

Installing macOS binary wheels
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If you are using Python from https://www.python.org, Homebrew, or Macports,
then you can use the standard pip installer to install Matplotlib binaries in
the form of wheels.

pip is installed by default with python.org and Homebrew Python, but needs to
be manually installed on Macports with ::

   sudo port install py38-pip

Once pip is installed, you can install Matplotlib and all its dependencies with
from the Terminal.app command line::

   python3 -m pip install matplotlib

You might also want to install IPython or the Jupyter notebook (``python3 -m pip
install ipython notebook``).

Checking your installation
^^^^^^^^^^^^^^^^^^^^^^^^^^

The new version of Matplotlib should now be on your Python "path".  Check this
at the Terminal.app command line::

  python3 -c 'import matplotlib; print(matplotlib.__version__, matplotlib.__file__)'

You should see something like ::

  3.10.0 /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/__init__.py

where ``3.10.0`` is the Matplotlib version you just installed, and the path
following depends on whether you are using Python.org Python, Homebrew or
Macports.  If you see another version, or you get an error like ::

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: No module named matplotlib

then check that the Python binary is the one you expected by running ::

  which python3

If you get a result like ``/usr/bin/python...``, then you are getting the
Python installed with macOS, which is probably not what you want.  Try closing
and restarting Terminal.app before running the check again. If that doesn't fix
the problem, depending on which Python you wanted to use, consider reinstalling
Python.org Python, or check your homebrew or macports setup.  Remember that
the disk image installer only works for Python.org Python, and will not get
picked up by other Pythons.  If all these fail, please :ref:`let us know
<reporting-problems>`.


.. include:: troubleshooting_faq.inc.rst