1

I want to plot a grid where each node in the grid is drawn by a dot, with a certain color code (taken from a vector stored in the node).

my grid

the grid here varies in size depending on the size of the simulations I am running. I have yet to figure out the relationship between the canvas size and the marker size. Now I use the following formula:

markersize = (figsize*figsize*dpi*dpi)/(xdim*ydim)
plt.scatter(X, Y, s=markersize/3, marker='s', c=Z, cmap=cm.rainbow)
plt.show()

that is I square the sigsize and the dpi (use 15 and 80 respectively), and divide by the dimensionality of the grid. Finally I divide this by 3 as I found this to work.

But I haven't been able to work out how to analytically get the right marker size. What I want is a grid where each square uses as much a space as it can but without "infringinig" on the other nodes' space, so that the markers overlap.

As far as I can read the figsize is given in inches. dpi is - dots per inch, and the markersize is specified in - points. If the points is the same as dots, you would then have dpifigsize amount of dots on each axis. The xdimydim is the amount of nodes in my grid. Dividing the pow(dpifigsize, 2) / xdimydim should then give the amounts of dots per node, and the right size for each marker I thought. But that made the markers too big. I diveded by 3 and it sort of worked practically for the sizes I usually run, but not for all. (I am guessing a point and a dot is not the same, but what is the relation?)

How do I work out the correct answer for this? Ideally I would like a very granular picture where I could zoom in an certain areas to get a finer look at the color nuances.

user1603472
  • 1,408
  • 15
  • 24
  • Well if you have an isotropic data where fig_size_x=fig_size_y you can do this: `marker_size = fig_x*fig_dpi/xdim. ax.scatter(x, y, z, marker='s',c=areaImg[x,y,z], s=marker_size, zdir='z', cmap=plt.cm.rainbow)`. Then to get the crisp structure you can play with the [interpolation](http://matplotlib.org/examples/images_contours_and_fields/interpolation_methods.html) – bazilevs31 Nov 25 '15 at 19:23

1 Answers1

0

If you want to control the marker size precisely and have it scale with the figure, you can use a patch instead of a regular marker. Here's an example:

from matplotlib import pyplot as plt
from matplotlib.patches import Circle

x = [1, 2, 3, 4, 5]
y = [1, 3, 1, 2, 4]
colors = [10, 215, 30, 100]

cmap = plt.cm.jet
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')

for (x, y, c) in zip(x, y, colors):
    ax.add_artist(Circle(xy=(x, y), radius=0.5, color=cmap(c)))      

ax.set_xlim(0, 6)
ax.set_ylim(0, 6)
plt.show()

You could also use a rectangle instead of a circle.

Molly
  • 13,240
  • 4
  • 44
  • 45
  • thanks for this suggestion. but i think iterating over all of these points would be too slow for me. is there any way to perform an exact calculation of the marker size for a scatter plot? – user1603472 Jan 29 '14 at 10:59