I figured out you can pass in the rasterized keyword to all of those to change the rasterization in the output.
Also the docs say for pcolormesh it defaults to the backend if not set. Therefore, in the case of a vector based it would output vectors if not set to rasterize.
Haven’t tested but curious. Lets say I want to output at 600dpi but I display images interactively at 100dpi. Does it always rasterize the image to the higher dpi? I had noticed this didn’t seem to occur in specgram but figured because the specgram is a relatively low resolution image that outputing at 600dpi doesn’t do anything because original image is already a low resolution. I would expect the other modes do do this where the image isn’t already output and have to rasterize the image when saving like pcolormesh and contour plots.
On Sat, Jul 28, 2012 at 1:43 PM, Jeffrey Spencer <jeffspencerd@…2015…87…> wrote:
Yes, specgram rasterizes and contourf is definately a vector specification which isn’t optimal for 100 levels.
I would switch to pcolormesh but the output file can’t be rasterizing the image. It outputs a huge file in .pdf (40X bigger than equivalent .png) and it looks like it is vector based not rasterized.
Basically, If you output specgram or imshow in .pdf or .png the file sizes are relatively comparable with .pdf, .eps, .svg being slightly larger due to embedding the picture.
If I output in pcolor, pcolormesh, contourf (with more than 100 levels) the file sizes are huge for .pdf, .eps, .svg which I’m assuming because vector based output. It also looks like vector based output because can see the lines it draws for contours. Could this possibly be a selection for these outputs to force raster based processing or is that not easy.
On Sat, Jul 28, 2012 at 3:26 AM, Eric Firing <efiring@…202…> wrote:
On 2012/07/26 10:26 PM, Jeffrey Spencer wrote:
Thanks, that is all good info to know. I change my data to log and
normalize it so the logNorm is just linear actually so specifying only
levels is fine. I’ll let you know if that doesn’t work properly for some
Ok, yeah I looked at pcolormesh quickly and can’t remember why I chose
originally when I wrote this to go with contourf but I use to only do
like 10 levels. I think it might be because use a log yaxis and think it
used to be a bit funky or couldn’t get it working properly but seemed
No, I don’t want to modify the ticks but the black lines around that
like how they are removed on the major axis in this example:
I want to remove the black lines also around the colorbar. Not the tick
marks. Does that make sense?
One more quick question out of curiosity noticing from saving plots to
.pdf from contourf and pcolormesh vs specgram. Specgram seems to output
the lines and text as vector graphics. Then imbeds the image. When
outputting from pcolormesh or contourf this isn’t the case. It tries to
write the lines or something else weird happens. Can you output to .pdf
from these and make the lines and text be vectors. Then the image output
as an image in the pdf like in specgram. Or is there a setting to do
this and specify the .dpi of the image in the .pdf.
Lines and text are output to pdf exactly the same by specgram, pcolormesh, and contourf. The difference should be only in the image part of the plot, which is rasterized for a specgram image and for the “quadmesh” produced by pcolormesh, but is a set of patches (vector specification, not rasterized) for contourf. Are you seeing results that are inconsistent with this expectation?
Thanks a lot,
On Fri, Jul 27, 2012 at 5:51 PM, Eric Firing <efiring@…202… > > > mailto:efiring@...120.....202...> wrote:
On 2012/07/26 9:20 PM, Jeffrey Spencer wrote: import numpy as np import matplotlib as mpl
X, Y = np.meshgrid(arange(20),arange(__20))
Z = np.arange(20*20) Z = Z.reshape(20,20)
logNorm = mpl.colors.Normalize(vmin=0,__vmax=200)
fig = mpl.pyplot.figure(10) ax = fig.add_subplot(111) surf = ax.contourf(X,Y,Z, 100, cmap=matplotlib.cm.jet, norm = logNorm) cbar = fig.colorbar(surf, shrink=0.70, norm=logNorm) show() OK, the basic problem here is that you are specifying 100 levels, which are being auto-selected to cover the actual data range; and the colorbar is doing what it is supposed to do, which is show the levels you actually have. Try leaving out the norm, and just specify the levels to cover what you want, more like this: surf = ax.contourf(X, Y, Z, np.arange(0, 200.1, 2), cmap=mpl.cm.jet, extend='both') cbar = fig.colorbar(surf, shrink=0.7) If you actually do want a log norm, you can pass that in to contourf and it will be passed on to colorbar; but most likely you should still specify the levels you want as an array, and not specify vmin and vmax in the norm. If you want log scaling, it may work better to simply plot the log of Z, and use the colorbar label to indicate that this is what you are doing. Note that with a recent change, you can use the set_under and set_over methods of the cmap to specify arbitrary colors, or no color, for the extended regions; or you can leave out the "extend" kwarg and not color the regions outside the range of your contour levels. In general, contourf is most appropriate when there is a moderate number of levels, well under 100; if you want that many gradations, then you might do better with pcolormesh or ax.pcolorfast or imshow. For those image-like methods, it is appropriate to use vmin and vmax, either directly, or in a norm. Eric