在ipython中更改imshow的分辨率 [英] Change resolution of imshow in ipython

查看:320
本文介绍了在ipython中更改imshow的分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ipython,其代码如下所示:

  image = zeros(MAX_X,MAX_Y)

#做一些复杂的事情来获取像素值...
#像素值现在在[0,1]中。

imshow(图片)

但是,生成的图片总是一样的分辨率,大约(250x250)。我认为图像的尺寸是(MAX_X x MAX_Y),但看起来并非如此。如何让ipython为我提供更高分辨率的图像?

解决方案

屏幕上显示图像的高度和宽度由。您也可以使用 gridspec


I am using ipython, with a code that looks like this:

image = zeros(MAX_X, MAX_Y)

# do something complicated to get the pixel values...
# pixel values are now in [0, 1].

imshow(image)

However, the resulting image always has the same resolution, around (250x250). I thought that the image's dimensions would be (MAX_X x MAX_Y), but that is seemingly not the case. How can I make ipython give me an image with a greater resolution?

解决方案

The height and width of the displayed image on the screen is controlled by the figure size and the axes size.

figure(figsize = (10,10)) # creates a figure 10 inches by 10 inches

Axes

axes([0,0,0.7,0.6]) # add an axes with the position and size specified by 
                    # [left, bottom, width, height] in normalized units. 

Larger arrays of data will be displayed at the same size as smaller arrays but the number of individual elements will be greater so in that sense they do have higher resolution. The resolution in dots per inch of a saved figure can be be controlled with the the dpi argument to savefig.

Here's an example that might make it clearer:

import matplotlib.pyplot as plt
import numpy as np

fig1 = plt.figure() # create a figure with the default size 

im1 = np.random.rand(5,5)
ax1 = fig1.add_subplot(2,2,1) 
ax1.imshow(im1, interpolation='none')
ax1.set_title('5 X 5')

im2 = np.random.rand(100,100)
ax2 = fig1.add_subplot(2,2,2)
ax2.imshow(im2, interpolation='none')
ax2.set_title('100 X 100')

fig1.savefig('example.png', dpi = 1000) # change the resolution of the saved image

# change the figure size
fig2 = plt.figure(figsize = (5,5)) # create a 5 x 5 figure 
ax3 = fig2.add_subplot(111)
ax3.imshow(im1, interpolation='none')
ax3.set_title('larger figure')

plt.show()

The size of the axes within a figure can be controlled in several ways. I used subplot above. You can also directly add an axes with axes or with gridspec.

这篇关于在ipython中更改imshow的分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆