Installing matplotlib under Windows - python

I'm trying to install matplotlib under Windows Vista. Both python itself and numpy are working for me.
I installed matplotlib via the executable basemap-1.0.2.win32-py2.7 and followed the official instructions. But running from matplotlib import * gives me the following error:
No module named matplotlib
Any ideas how to get matplotlib working?

you can install by pip install matplotlib
Make sure that you already installed setuptools, numpy, python-dateutil, pytz, pyparsing, and cycler before that.

basemap is not the installer for matplotlib.
basemap is a library of the matplotlib toolkit for plotting 2D data on maps, you need to indepently install matplotlib to use it.
You can get matplotlib from here

from pylab import *
This works on a proper the default scipy/pylab/matplotlib setup. And to get you started:
> hist(randn(10000))
> show()
Matplotlib is a part of the pylab suite

If you are installing matplotlib under windows using anaconda. Here are the steps..
I am using Anaconda 1.8.7
Goto your Anaconda Navigator and choose Environments
Click on the arrow and choose Open terminal
Type conda install matplotlib
That should do the trick. For specific versions and to install onto specific environments within annaconda you can utilise the = and -n / name option
https://conda.io/docs/commands/conda-install.html
Matplotlib Installation using command prompt / Annaconda Terminal

Open Command Prompt
C:\Users\Uname>python -m pip install matplotlib
Matplotlib requires some of the following dependencies:
FreeType libpng NumPy setuptools cycler dateutil kiwisolver pyparsing

Related

Pipenv install matplotlib

I'm having a lot of difficulty installing matplotlib in my pipenv, I believe due to the non-python dependencies.
The error I am getting is
Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
This is on MacOS X (High Sierra). I have installed libpng freetype and pkg-config via brew, but this does not seem to resolve the issue.
My hope for this pipenv is for it to be deployed to Heroku, if that makes any difference.
I resolved this error by following the instructions in this answer while also using this document to find where the matplotlibrc file is located.
To do this inside my pipenv I ran the following code:
python
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
Using the output I navigated to the matplotlibrc file within my virtual environment and added backend: TkAgg to the file.
This resolved my issue. Hopefully this question can be of help to others!
Before trying as #brian suggested, for me, it worked by just adding matplotlib.use('TkAgg') after import matplotlib and before from matplotlib import pyplot
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot
Environment
This is on MacOS X (High Sierra)
Python 3.7 version
pipenv, version 2018.7.1

Taylor diagram in python by using skill_metrics

I tried to use skill_metris to create taylor diagram. But I am getting error saying that
module 'matplotlib.colors' has no attribute 'to_rgb'
example code:
import skill_metrics as sm
sm.taylor_diagram(0.22,0.52,0.32)
Answer can be find on github project FAQ
https://github.com/PeterRochford/SkillMetrics/wiki/FAQ
From site:
A3. This problem occurs when using an earlier version of matplotlib
than 2.0.0. The latter is distributed with Python 3.6 but standard
distributions of Python 2.7 are usually distributed with earlier
versions of matplotlib (e.g. 1.3.1 and 1.5.0). To check what version
of matplotlib you are using execute the following statements at the
Python command line (or within a script):
import matplotlib
matplotlib.__version__
I order to get newer matplotlib version you can use following pip command. pip install -U matplotlib.
I managed to solve this issue by installing the following modules on google colab:
! pip install XlsxWriter
! pip install SkillMetrics

get Error: 'no module named 'matplotlib.style' while matplotlib works fine

I'm using PyCharm on an ubuntu 14.04.1 LTS with python3. I want to use the 'ggplot' style module, but I get an 'no module named' error. Matplotlib 1.3.1 is installed and works fine (I updated it recently).
import matplotlib as mpl
import matplotlib.style as mplstyle
mplstyle.use('ggplot')
ImportError: No module named 'matplotlib.style'
I also checked for the matplotlibrc file and matplotlibtool and everything seems to be as the documentation recommends. Anyone knows, what I can do?
According to What's new in matplotlib, the style package was added to matplotlib since version 1.4.
So, check your matplotlib version by,
$ pip freeze | grep matplotlib
matplotlib==1.3.1
Upgrade matplotlib to the newest version by,
$ sudo pip install matplotlib --upgrade
$ pip freeze | grep matplotlib
matplotlib==1.5.1
This works fine for me.
import matplotlib.pyplot as plt
plt.style.use('ggplot')

Importing mpl_toolkits.basemap on Windows?

I have recently started using Python 3.5 and Anaconda on my Windows pc. I am trying to plot a map. However, When I am in my Jupyter notebook and i type the command
import mpl_toolkits.basemap
I get an error message saying 'no module name' 'mpl_toolkits.basemap'
However, I have the module downloaded and in the same C:\Users\Geena file as my .matplotlib, .ipython, .jupyter files, etc.
Anyone know how I can fix this?
I've had this issue with anaconda on my windows 7.
I found the way to fix it with python 3.5:
You need to run with administrator rights "Anaconda Prompt" and in "Anaconda Prompt" run following command:
conda install -c conda-forge basemap-data-hires=1.0.8.dev0
, it will show new packages that you need to install and will ask you to install it - say 'Yes'.
After that new packages will be installed and the issue "import mpl_toolkits.basemap" will be fixed.
Thank you.
Currently, basemap is not compatible with python 3 for windows users. So, if you try conda install basemap and you have python 3 installed in windows, you'll see a message pointing out that a conflict was found with python 3.
I solved this by installing a python 2.7 environment. Try this:
http://conda.pydata.org/docs/py2or3.html
Then you just activate the python 2 environment. For example: activate py27 (py27 is the identifier of my python 2.7 environment).
After that, you can run conda install basemap with no conflict.
I'm using python 3.6.4 on Windows 7 Family Premium (32bit).
Because I was a bit frustrated by the message "no module named 'mpl_toolkits.basemap'", I searched for and tried a dozen of solutions without success : various versions, building from source, problems with VS version, nmake, ... You all know what I mean ;-)
I finally found a quite simple solution that works perfectly well for me :-) Here it is !
from here I downloaded basemap‑1.1.0‑cp36‑cp36m‑win32.whl
I changed the current dir to my download dir
I installed the wheel with python -m pip basemap‑1.1.0‑cp36‑cp36m‑win32.whl
I did the same for matplotlib‑2.2.3‑cp36‑cp36m‑win32.whl
You DO read the versions correctly : matplotlib 2.2.3 and basemap 1.1.0
Everything works fine for me and I finally can plot OSM POI's on a map of Belgium, without any 'trickery' at import :
import requests # to fetch OSM data
import json # to get the response
from mpl_toolkits.basemap import Basemap # ... Belgium is there !
import numpy as np # for arrays
import matplotlib.pyplot as plt # to build the populated map
Big big thanks to Christoph Gohlke (Danke Dir Christoph !) who did all the wonderful job !
When you have Anaconda, you don't download modules anywhere. In your command prompt, you type
conda install basemap
and it is installed with all its dependencies.
Anaconda requires an unusual install command for basemap 1.0.7.
https://anaconda.org/anaconda/basemap
To install this package with conda run:
conda install -c https://conda.anaconda.org/anaconda basemap
I just had this issue as well. All you need to do is update matplotlib by doing the following:
pip install --upgrade matplotlib
mpl_toolkits is part of matplotlib and just needs to be updated.
If you're using anaconda, the easiest thing to do is described here: in the conda prompt (as admin), type conda install -c anaconda basemap.
For people of the future : "Basemap is deprecated in favor of the Cartopy project."
https://matplotlib.org/basemap/users/intro.html#cartopy-new-management-and-eol-announcement

Problems installing/importing Basemap

I have installed Anaconda (version 1.6.2) installed on my 64 bit machine. It comes with a great set of libraries, but I also need Basemap, part of matlibplot, but it is not included with the Anaconda install. I attempted to install Basemap and move the files in the Anacaonda\Lib\site-packages\mpl_toolkits directory since it is part of the mpl_toolkits library. However when I attempt to run a script, I keep getting the errors:
"No module named _geoslib"
"Cannot import pyproj"
I found the pyproj library. Do I need it? Where can I find geoslib? And how do I get Basemap to work?
What you nees is to change your path first, by:
$ export PATH=~/anaconda/bin:$PATH
and then,
$ conda install basemap
( I assumed you are in Linux)
source:http://docs.continuum.io/anaconda/faq.html
If your on Windows try installing Basemap from the Sourceforge executable, these should include GEOS and PROJ4 dependencies of Basemap.
I believe all that is needed is to update matplotlib, I just had this problem and doing this worked for me:
pip install --upgrade matplotlib

Categories