Closest to “Mathematica Graphics[]" drawing environment for Python

Being only familiar with Mathematica and its Graphics, I have now to learn to draw Graphics using Python for a server.

Mostly conditional combination of simple shape.

What would be a package for Python that make drawing Graphics as close as possible as the Mathematica Graphics environment ?

For Example, I would need to do such thing as in :

https://mathematica.stackexchange.com/questions/1010/2d-gaussian-distribution-of-squares-coordinates#comment2475_1010

• First, having only just read the FAQ, I strongly suspect that this is a question more suited to StackOverflow. Second, you should probably take a step back before asking your question on SO--ask the question in the context of what you wish to achieve, and not in the context of what you think the solution might be. Jan 31, 2012 at 15:46
• @Eric, I post that here, after suggestion it does not belong neither to So or Mathematica.... I believe I am asking the question in the context of what I am trying to achieve, since I show the type of things I need to do with it above....
– 500
Jan 31, 2012 at 20:04
• matplotlib, along with numpy and scipy, are the usual starting point for mathematical plotting, unless you wanted a more general graphics library Feb 1, 2012 at 11:13

1 Answer

Matplotlib is what you want.

The special sauce is a rendering technology known as agg which i believe stands for anti-grain geometry. The results is that this library produces publication-quality graphics across a staggering range of plot families.

My plot isn't all that much like the one in linked to in your Question, but that's only because the colors are different.

That sort of plot is trivial in Matplotlib. Here's the code i used to create it.

``````import numpy as NP
from matplotlib import pyplot as MPL
import matplotlib.cm as CM

M = NP.random.randint(0, 25, 100**2).reshape(100, 100)
M = NP.where(M < 20, 0, M)

fig = MPL.figure(frameon='False')
ax1 = fig.add_subplot(111)
ax1.imshow(M, cmap=CM.Accent, interpolation='nearest')
ax1.set_xticks([])
ax1.set_yticks([])
MPL.show()
``````