简体   繁体   中英

How does matplotlib.pyplot.imshow 'squeeze' the data when there is not enough resolution to show all data?

When using matplotlib.pyplot.imshow , say I have a 100x100 array, but the image resolution is only 50x50, how are the data transformed or selected for plotting? What parameters control this behavior?

All I can find is in matplotlibrc , there is #image.resample : False but I couldn't find documentation on what are the options. Does #image.interpolation have any impact?

Thanks!!

There are several interpolation methods available in the library as seen here . It looks like interpolation is an optional parameter to the imshow() method.

So I tried some tests, I think the extra data just get skipped rather than any form of transformation, at least with interpolation='none' and interpolation=bilinear . Note data points get stretched unevenly in some cases. I don't have enough reputation to post figures, but here is the code. (The plots needs zoom in to see).

import matplotlib.pyplot as plt
import numpy as np

np.random.seed(1)
grid = np.random.rand(10, 10)

fig=plt.figure(figsize=(1,1),frameon=False)
plt.Axes(fig, [0., 0., 1., 1.])
plt.axis("off")
plt.subplots_adjust(left=0,right=1,bottom=0,top=1)

plt.imshow(grid,interpolation='none',cmap='jet')

plt.savefig("test_dpi15_none.png",bbox_inches=0,pad_inches=0, dpi=15)
plt.savefig("test_dpi10_none.png",bbox_inches=0,pad_inches=0, dpi=10)
plt.savefig("test_dpi5_none.png",bbox_inches=0,pad_inches=0,dpi=5)
plt.savefig("test_dpi2_none.png",bbox_inches=0,pad_inches=0,dpi=2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM