views:

3156

answers:

3

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 pl.show() and then save it. Or directly use plt.savefig('filename.ps') in the code to save it. The problem is this: when I use pl.show() 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?

+2  A: 

If you haven't, you should try saving in a rasterizing engine -- save it to a PNG file and see if that fixes it. If you need a vector plot, try saving to PDF and converting with an external utility. I've also had problems before with the PS engine that were resolved by saving with the Agg or PDF engines and converting externally.

Matt
Yeah, this work around works. BTW we do the same kind of work.
Alex
+2  A: 

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)
savefig('foo.ps')

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?

Jouni K. Seppänen
A: 

Have you tried the ',' point shape? Maybe you can play with markersize as well, with this shape?

EOL