I have a medium-sized array (e.g. 1500x3000) that I want to plot at scale since it is an image. However, the vertical and horizontal scales are very different. For simplification let say that there is one meter/row and 10/column. The plot should then produce an image which is c. 1500x30000. I use the kwarg extent for the scales and aspect = 1 to avoid deformation. Either by using the plotting windows (QT4) and imshow() or by using savefig(), I never succeeded in producing the image at scale and at full resolution.
I have looked to many proposed solutions as indicated in here, here, or here and there or there in case it was a bug. I have altered my matplotlibrc and placed it in ~/.config/matplotlib to try forcing the my display / savefig options but to no avail. I also tried with pcolormesh() but without success. I use python 2.7 and matplotlib 1.3 from the repo of Ubuntu 14.04 and QT4Agg as a backend. I tried TkAgg too but it is slow and gives the same results. I have the impression that in the x axis the resolution is right but it is definitely downsampled in the vertical direction. Here is a piece of code which should simulate my issue.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors
R, C = 1500, 3000
DATA = np.random.random((R, C))
DATA[::2, :] *= -1 # make every other line negative
Yi, Xi = 1, 10 # increment
CMP = 'seismic'
ImageFormat ='pdf'
Name = 'Image'
DataRange = (np.absolute(DATA)).max() # I want my data centred on 0
EXTENT = [0, Xi*C, 0 ,Yi*R]
NORM = matplotlib.colors.Normalize(vmin =-DataRange, vmax= DataRange, clip =True)
for i in range(1,4):
Fig=plt.figure(figsize=(45, 10), dpi = 100*i, tight_layout=True)
Fig.suptitle(Name+str(i)+'00DPI')
ax = Fig.add_subplot(1, 1, 1)
Plot = ax.imshow(DATA, cmap=plt.get_cmap(CMP), norm = NORM, extent = EXTENT, aspect = 1, interpolation='none')
ax.set_xlabel('metres')
ax.set_ylabel('metres')
Fig.savefig(Name+str(i)+'00DPI.'+ImageFormat, format = ImageFormat, dpi = Fig.dpi)
plt.close()
In imshow(), interpolation = 'none' or 'nearest' or 'bilinear' does not change the resolution for some reason although I think it is supposed to at least in the Qt4 window if I do show() instead of savefig(). Notice that the resolution is the same in the figures saved whatever you setup in the plt.figure(dpi=).
I am out of idea and at the limit of my understanding on how things work with this system. Any help is very welcome.
Thanks in advance.
plt.savefig("test.svg")
– Hygrometer