Python plotting: How can I make matplotlib.pyplot stop forcing the style of my markers?


I am trying to plot a bunch of data points (many thousands) in Python using matplotlib so I need each marker to be very small and precise. How do I get the smallest most simple marker possible? I use this command to plot my data:

 matplotlib.pyplot( x , y ,'.',markersize=0.1,linewidth=None,markerfacecolor='black')

Then I can look at it either with and then save it. Or directly use plt.savefig('') in the code to save it. The problem is this: when I use to view the file in the GUI it looks great with small tiny black marks, however when I save from the show() GUI to a file or use directly savefig and then view the ps I created it looks different! Each marker has gained a little blue halo around it (as if it started at each point to connect them with the default blue lines, but did not) and the style is all wrong. Why does it change the style when saved? How do I stop python from forcing the style of the markers? And yes I have looked at some alternative packages like CairoPlot, but I want to keep using matplotlib for now.

Update: It turns out that the save to PNG first makes the colors turn out okay, but it forces a conversion of the image when I want to save it again as a .ps later (for inclusion in a PDF) and then I lose quality. How do I preserve the vector nature of the file and get the right formatting?

8/8/2009 10:14:56 AM

Accepted Answer

For nice-looking vectorized output, don't use the '.' marker style. Use e.g. 'o' (circle) or 's' (square) (see help(plot) for the options) and set the markersize keyword argument to something suitably small, e.g.:

plot(x, y, 'ko', markersize=2)

That '.' (point) produces less nice results could be construed as a bug in matplotlib, but then, what should "point" mean in a vector graphic format?

3/12/2009 12:58:58 PM

Have you tried the ',' point shape? It creates "pixels" (small dots, instead of shapes).

You can play with the markersize option as well, with this shape?

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow