Skip to content Skip to sidebar Skip to footer

How Do You Get The Marker Squares To Be Exact Squares With Matplotlib?

To begin with, it is important that I do this with plt.scatter and not by iterating over the points (patches), because with my real data I have huge amounts of data points. The qu

Solution 1:

The general answer is probably Patches, not marker squares, however slow it is. However, using the grid nature of the sample you show, there's a much easier way, and you can still do other plotting over it:

import matplotlib.pyplot as plt
from matplotlib import cm
import numpy.random as nr
quilt = nr.random((4,4))


plt.imshow(quilt, interpolation='none', aspect='equal', cmap=cm.jet)
plt.scatter([1,2,3],[3,0,1])
plt.plot([0,1,1.4, 2.3, 3.5],[0,1,2,3,2])
plt.show()

enter image description here

You can change the axis ticks to represent your data units, customize the colormap to have transparent squares for missing data, embed the imshow as a subplot in another figure, etc. etc.


Post a Comment for "How Do You Get The Marker Squares To Be Exact Squares With Matplotlib?"