How to install matplotlib

How to install matplotlib

Installing FAQ¶

Report a compilation problem¶

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

The first thing to try is a 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 IDLE which add additional complexities. Open up a UNIX shell or a DOS command prompt and run, for example:

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 configuration process, governed by the matplotlibrc configuration file which contains instructions within and the concept of the Matplotlib backend.

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:

OSX Notes¶

Which python for OSX?¶

Other options for a fresh Python install are the standard installer from python.org, or installing Python using a general OSX package management system such as homebrew or macports. Power users on OSX 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.

Installing OSX 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

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

Checking your installation¶

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

You should see something like

where 3.0.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

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

Installation#

Installing an official release#

Matplotlib releases are available as wheel packages for macOS, Windows and Linux on PyPI. Install it using pip :

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

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

Third-party distributions#

Various third-parties provide Matplotlib for their environments.

Conda packages#

Matplotlib is available both via the anaconda main channel

as well as via the conda-forge community channel

Python distributions#

Matplotlib is part of major Python distributions:

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

Installing from source#

If you are interested in contributing to Matplotlib development, running the latest source code, or just like to build everything yourself, it is not difficult to build Matplotlib from source.

For those using Visual Studio, make sure «Desktop development with C++» is selected, and that the latest MSVC, «C++ CMake tools for Windows,» and a Windows SDK compatible with your version of Windows are selected and installed. They should be selected by default under the «Optional» subheading, but are required to build matplotlib from source.

The easiest way to get the latest development version to start contributing is to go to the git repository and run:

If you’re developing, it’s better to do it in editable mode. The reason why is that pytest’s test discovery only works for Matplotlib if installation is done this way. Also, editable mode allows your code changes to be instantly propagated to your library code without reinstalling (though you will have to restart your python process / kernel):

If you’re not developing, it can be installed from the source directory with a simple (just replace the last step):

To run the tests you will need to install some additional dependencies:

Then, if you want to update your Matplotlib at any time, just do:

There is more information on using git in the developer docs.

The following instructions in this section are for very custom installations of Matplotlib. Proceed with caution because these instructions may result in your build producing unexpected behavior and/or causing local testing to fail.

If you would like to build from a tarball, grab the latest tar.gz release file from the PyPI files page.

We provide a mplsetup.cfg file 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. This file will be particularly useful to those packaging 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.

Installing for development#

Frequently asked questions#

Report a compilation problem#

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

The first thing to try is a 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 IDLE which add additional complexities. Open up a UNIX shell or a DOS command prompt and run, for example:

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 configuration process, governed by the matplotlibrc configuration file which contains instructions within and the concept of the Matplotlib backend.

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:

OSX Notes#

Which python for OSX?#

Other options for a fresh Python install are the standard installer from python.org, or installing Python using a general OSX package management system such as homebrew or macports. Power users on OSX 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.

Installing OSX 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

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

Checking your installation#

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

You should see something like

where 3.0.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

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

Installing¶

Installing an official release¶

Matplotlib and its dependencies are available as wheel packages for macOS, Windows and Linux distributions:

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

Although not required, we suggest also installing IPython for interactive use. To easily install a complete Scientific Python stack, see Scientific Python Distributions below.

Test data¶

The wheels ( *.whl ) on the PyPI download page do not contain test data or example code.

If you want to try the many demos that come in the Matplotlib source distribution, download the *.tar.gz file and look in the examples subdirectory.

To run the test suite:

Third-party distributions of Matplotlib¶

Scientific Python Distributions¶

Anaconda and Canopy and ActiveState are excellent choices that «just work» out of the box for Windows, macOS and common Linux platforms. WinPython is an option for Windows users. All of these distributions include Matplotlib and lots of other useful (data) science tools.

Linux: using your package manager¶

If you are on Linux, you might prefer to use your package manager. Matplotlib is packaged for almost every major Linux distribution.

Installing from source¶

Once you have satisfied the requirements detailed below (mainly Python, NumPy, libpng and FreeType), you can build Matplotlib.

We provide a setup.cfg file 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. This file will be particularly useful to those packaging Matplotlib.

Dependencies¶

Matplotlib requires the following dependencies:

Optionally, you can also install a number of packages to enable better user interface toolkits. See What is a backend? for more details on the optional Matplotlib backends and the capabilities they provide.

For better support of animation output format and image file formats, LaTeX, etc., you can install the following:

Matplotlib depends on non-Python libraries.

On Linux and OSX, pkg-config can be used to find required non-Python libraries and thus make the install go more smoothly if the libraries and headers are not in the expected locations.

The following libraries are shipped with Matplotlib:

Building on Linux¶

It is easiest to use your system package manager to install the dependencies.

If you are on Debian/Ubuntu, you can get all the dependencies required to build Matplotlib with:

If you are on Fedora, you can get all the dependencies required to build Matplotlib with:

If you are on RedHat, you can get all the dependencies required to build Matplotlib by first installing yum-builddep and then running:

These commands do not build Matplotlib, but instead get and install the build dependencies, which will make building from source easier.

Building on macOS¶

The build situation on macOS is complicated by the various places one can get the libpng and FreeType requirements (MacPorts, Fink, /usr/X11R6), the different architectures (e.g., x86, ppc, universal), and the different macOS versions (e.g., 10.4 and 10.5). We recommend that you build the way we do for the macOS release: get the source from the tarball or the git repository and install the required dependencies through a third-party package manager. Two widely used package managers are Homebrew, and MacPorts. The following example illustrates how to install libpng and FreeType using brew :

If you are using MacPorts, execute the following instead:

After installing the above requirements, install Matplotlib from source by executing:

Note that your environment is somewhat important. Some conda users have found that, to run the tests, their PYTHONPATH must include /path/to/anaconda/. /site-packages and their DYLD_FALLBACK_LIBRARY_PATH must include /path/to/anaconda/lib.

Building on Windows¶

The Python shipped from https://www.python.org is compiled with Visual Studio 2015 for 3.5+. Python extensions should be compiled with the same compiler, see e.g. https://packaging.python.org/guides/packaging-binary-extensions/#setting-up-a-build-environment-on-windows for how to set up a build environment.

Since there is no canonical Windows package manager, the methods for building FreeType, zlib, and libpng from source code are documented as a build script at matplotlib-winbuild.

There are a few possibilities to build Matplotlib on Windows:

Wheel builds using conda packages¶

This is a wheel build, but we use conda packages to get all the requirements. The binary requirements (png, FreeType. ) are statically linked and therefore not needed during the wheel install.

Set up the conda environment. Note, if you want a qt backend, add pyqt to the list of conda packages.

How to install matplotlib python

In this Python tutorial, we will discuss How to install matplotlib python with all the required dependencies to use the package in the data visualization in python and we shall also cover the following topics:

How to install matplotlib python

You can install matplotlib library to use it in python in all the three major operating systems commonly used:

You can install matplotlib in any of these operating systems either by using the pip command (using the python package manager) to install the released wheel packages available, or by creating a separate virtual environment for matplotlib from other installations of the python and matplotlib, or by using another environment such as anaconda which provides conda as a package manager to install packages.

NOTE –

How to install matplotlib python ubuntu

How to install matplotlib python using pip in Linux (Ubuntu)

You can install matplotlib for python in any of the Linux distributions including Ubuntu, by using the python package manager which provides the pip command to install any wheel package released for python. First, make sure that you have installed python and pip in your system. If you don’t have pip installed, first you have to install it, then install the matplotlib using pip. Execute the below commands in the terminal:

In the above commands,

You can check if matplotlib is successfully installed on your system by executing the command below in the terminal:

How to install matplotlib python Linux package manager

In Linux, python is pre-installed with the OS distribution, and if you are using that version, then you can install matplotlib by using Linux package manager, Different distributions have different package managers:

How to install matplotlib python venv in Linux

You can install matplotlib in a virtual development environment in Linux, by using Python’s virtual environment venv to create a virtual environment. The steps for doing it are given below:

The above command activates the development environment. You have to activate the development environment in the shell first, whenever you start working on the matplotlib.

Now, you can import the matplotlib package and use it in your development environment.

How to install matplotlib python windows

How to install matplotlib python pip in Windows

You can install matplotlib for python in a Windows OS, by using the python package manager which provides the pip command to install any wheel package released for python.

First, make sure that you have installed python and pip in your system. If you don’t have pip installed, first you have to install it, then install the matplotlib using pip. Execute the below commands in the cmd:

The above command is the same as we have done in Linux distribution in the above topic.

You can check if matplotlib is successfully installed on your system by executing the command below in the cmd:

How to install matplotlib python venv in Windows

You can create a virtual environment in python and configure it for the development of matplotlib in Windows by following the given steps:

The above command activates the development environment. You have to activate the development environment in the shell first, whenever you start working on the matplotlib.

The above commands are already discussed in the previous topic.

How to install matplotlib python mac

How to install matplotlib python pip in macOS

You can install matplotlib for python in a macOS, by using the python package manager which provides the pip command to install any wheel package released for python. First, make sure that you have installed python and pip in your system. If you don’t have pip installed, first you have to install it, then install the matplotlib using pip. Execute the below commands in the cmd:

The above command is also the same as we have done and discussed for the Linux distribution.

You can check if matplotlib is successfully installed on your system by executing the command below in the terminal:

How to install matplotlib python venv in macOS

The steps to create a dedicated development environment for the matplotlib python in macOS are the same as we have done and discussed for the Linux distribution.

How to install matplotlib python conda

Matplotlib is also part of some major Python distributions like an anaconda. So, you can install matplotlib in this distribution of python which provides its environment for the matplotlib. Anaconda is available for all three major operating systems, Linux, Windows, macOS. You can use the package manager provided by anaconda that is conda to install the matplotlib. You must have installed anaconda in your system then you can execute the command below in the cmd /conda prompt/terminal:

The above command will install the matplotlib in the anaconda development environment from the anaconda main channel.

You can install matplotlib from the anaconda community channel also by executing the command below.

How to install matplotlib python3

If you are using python3 then use pip3 in place of pip to install the matplotlib. All the installation process is same as given in above topics, just use pip3 instead.

How to install matplotlib python2

If you are using python2 then use pip to install the matplotlib. All the installation process is same as given in above topics.

You may also like reading the following articles.

In this Python tutorial, we have discussed How to install matplotlib python with all the required dependencies to use the package in the data visualization in python and we have also covered the following topics:

How to install matplotlib. Смотреть фото How to install matplotlib. Смотреть картинку How to install matplotlib. Картинка про How to install matplotlib. Фото How to install matplotlib

Entrepreneur, Founder, Author, Blogger, Trainer, and more. Check out my profile.

How to Install Matplotlib on Linux?

Matploptib is a low-level library of Python which is used for data visualization. It is easy to use and emulates MATLAB like graphs and visualization. This library is built on the top of NumPy arrays and consist of several plots like line chart, bar chart, histogram, etc. It provides a lot of flexibility but at the cost of writing more code.

Environment Setup:

Matplotlib is an overall package for creating static, animated, and interactive visualizations in Python. It literally opens up a whole new world of possibilities for you! Especially when it is used with Numpy or Pandas library, one can do unimaginable things. The plots give may give a new insight altogether. Now, the question arises i.e. How to make it running on your computer? But a more primary question would be, what are its pre-requisites or as we call it, dependencies for the software to run on your computer?

Dependencies:

Installation on Linux:

We will use the pip command to install this module. If you do not have pip installed then refer to the article, Download and install pip Latest Version.

To install Matplotlib type the below command in the terminal:

You will get the following message once the installation is complete:

How to install matplotlib. Смотреть фото How to install matplotlib. Смотреть картинку How to install matplotlib. Картинка про How to install matplotlib. Фото How to install matplotlib

Let’s see some examples of using matplotlib:

Example 1: Creating Line plots

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *