Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
When writing out plots in vector graphics formats, the image data can be shifted relative to the axes window.
Here is a list of things I've noticed about the problem:
- When data is shifted outside the axes window, it is clipped. Sometimes the data will be shifted entirely outside the axes window and the plot will appear blank.
- I've observed the problem in ps/eps/pdf/svg output files.
- The interpolation method used seems to have an effect on the shifted result.
- All of the image data is contained within the output file and can be retrieved using a program like inkscape (although some digging is required)
- The shift seems to be different in different viewers. For example, pdf output looks okay in Okular but not in xpdf.
There have been a couple of emails about this on the users mailing list. Benjamin Root verified the problem. Eric Firing suggested that it might be a truncation error bug and suggested the following:
I thought it might come from the use of str() instead of repr() when
generating the concat matrix in the ps backend, but that's not it. I'm
suspecting it may be inherent in the ps language, when one uses a matrix
to make an enormous translation in one direction, and then uses
translate to sling everything back in the other direction. Either that,
or some sort of "snapping" is going on.
--Chad
Here are some scripts that can be used to reproduce the problem:
importmatplotlib.pyplotaspltfrommatplotlib.colorsimportLogNormimgData= [[1.0/(x)+1.0/(y)forxinrange(1,100)]foryinrange(1,100)]tMin=734717.945208tMax=734717.946366# Case 0: WorksCase0={"id":0,"interp":None,"extents":(tMin,tMax,1,100)}# Case 1: WorksCase1={"id":1,"interp":"none","extents":(1,100,1,100)}# Case 2: Doesn't workCase2={"id":2,"interp":"none","extents":(tMin,tMax,1,100)}forCasein (Case2,Case1,Case0):plt.figure(Case["id"])axImg=plt.subplot(111)axImg.imshow(imgData,norm=LogNorm(),interpolation=Case["interp"],extent=Case["extents"])axImg.set_aspect('auto')forfiletypein ["png","eps","pdf","svg"]:plt.savefig("imageshift-Case{0}.{1}".format(Case["id"],filetype))
# modified by Eric Firingimportmatplotlib.pyplotaspltfrommatplotlib.colorsimportLogNormimgData= [[1.0/x+1.0/yforxinrange(1,10)]foryinrange(1,10)]tMin=1000000066# Shifted by halftMin=100000066# Blank!tMin=10000066# OKtMax=tMin+10# The following combination is also shifted by halftMin=10000066.1# adding the 0.1 doesn't make a differencetMax=tMin+1printtMin,tMaxaxImg=plt.subplot(111)axImg.imshow(imgData,norm=LogNorm(),extent=(tMin,tMax,1,10),interpolation='none',origin="upper")axImg.set_aspect('auto')plt.savefig("imageshift.png")plt.savefig("imageshift.eps")plt.savefig("imageshift.pdf")