Matplotlib 3D plotting: how to import

For 3D plotting to work in Matplotlib, near the beginning of the first .py file you use to start your program, you must have imports in this order:

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

If you try importing Axes3D in a later function that actually does the 3D plotting, it may give a runtime error.

If you feel you may use either function as an entry point, you can put the above 3 lines of code in both functions.

Autoscaling imagesc() plot and imshow() plots

Octave 3.8 has default axis scaling that scales x and y axes proportionally to the axes values. So if one axis values span a much wider range than the other axis, the smaller span axis gets very thin.

You can simply insert the line
axis(‘normal’) after imagesc()

In Matplotlib 1.3, the same issue occurs, which can be covercome with the option aspect=’auto’

Matplotlib in Cygwin 64-bit for Python 3 and Python 2.7

It is pretty simple to install matplotlib for Python 3 and Python 2.7 in Cygwin.

pkg-config ghostscript libfreetype-devel libpng-devel python-gtk2.0 libgtk2.0-devel gcc-g++ git

git clone git://
cd matplotlib
python install

or for python 3, do:
python3 install

$ python
Python 2.7.5 (default, Oct 2 2013, 22:34:09)
[GCC 4.8.1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__

$ python3
Python 3.2.5 (default, Oct 2 2013, 22:58:11)
[GCC 4.8.1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__

Note: to actually use matplotlib to create a visible figure, you need a basic X11 system running (install xinit, etc in Cygwin) and type
and then start python from inside X11 terminal.

Matplotlib Python3: fixing pyplot.imshow()

I have noticed on my Ubuntu 14.04 PCs and have seen other OSs having issues with python3 and matplotlib.pyplot.imshow().

Errors like:

NotImplementedError: Surface.create_for_data: Not Implemented yet.

and getting blank images.

I fixed the problem by switching the matplotlib backend as follows:
1) placing a file named “matplotlibrc” in the directory of my Python .py code (current working directory), with the contents
backend : qt4agg
2) installing the prerequisities:
sudo apt-get install python3-pyqt4 python3-sip