Matplotlib 2 in Cygwin 64-bit on Windows for Python 3 and Python 2.7

Related: easy pip install matplotlib without commpling


Matplotlib Cygwin manual compile

This method is NOT normally needed.
Just python -m pip install matplotlib normally.

  1. at Windows Command Prompt:
    setup-x86_64 -P pkg-config ghostscript libfreetype-devel libpng-devel libgtk2.0-devel gcc-g++ git openbox python3-numpy python3-pyqt5 python3-devel
    
  2. at Cygwin Terminal:
    python -m pip install matplotlib
    

Alternative: Matplotlib compile

You can just use the process above, unless you want to compile Matplotlib on Cygwin from source code for the latest Matplotlib beta.

git clone git://github.com/matplotlib/matplotlib.git

python -m pip install -e .

Test

python 

Python 3.6.1

import matplotlib
matplotlib.__version__

‘2.0.0’

visible figures

To create visible Matplotlib figures in Cygwin, start the X11 system by:

  1. Windows Start button → All App → Cygwin-X → Openbox.
  2. Openbox desktop: Right click → Terminals → Xterm.

Test the Matplotlib / Cygwin-X / Openbox configuration from the Cygwin X11 Openbox Xterm terminal:

from numpy.random import rand
import matplotlib

matplotlib.use('qt5agg') #must be before other matplotlib commands

from matplotlib.pyplot import figure,show

figure().gca().imshow(rand(100,100))
show()

You can permanently set default Cygwin Matplotlib backend to qt5agg.

Save figures

Even without the X11 desktop, create and save invisible figures to .eps, .png, .svg, etc. by using savefig().

from matplotlib.pyplot import figure,show

fg=figure()
ax=fg.gca()
fg.savefig('test.png')

Leave a Comment