Matplotlib图形大小 [英] Matplotlib figure size

查看:84
本文介绍了Matplotlib图形大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试验 Matplotlib(请参阅最近的问题:

正如我在上面的评论中提到的,我不知道这是否是您想要的,但是您可以看到刻度与每个补丁不对齐.因此,如果希望它们对齐,可以将 plt.yticks()调用上的 np.arange()调用更改为以下内容:

  plt.yticks(np.arange(-0.5,5.5),[utilities.num2pid [k] for range in k(5)])

输出:

希望这会有所帮助.

I have been experimenting with Matplotlib (see recent question: here)

I am trying to modify the size of the graph output by experimenting with:

plt.figure(figsize=(20, 12.5)) 

But it never seems to work as expected - I use larger numbers to try to increase the height of the graph but it does not make it smaller. Any thoughts on making the graph larger. The link question above has an attached image that I currently get with figsize=(20,12.5).

Thanks!

解决方案

Well, to answer your question, you can use the aspect parameter on imshow() call.

From the documentation:

Controls the aspect ratio of the axes. The aspect is of particular relevance for images since it may distort the image, i.e. pixel will not be square.

In this case, I think it does not matter that "pixels" look square, so you could add the aspect parameter to the plt.imshow() call and set a value.

plt.imshow(field_matrix, interpolation='nearest', cmap=cmap, aspect=7)

Now, the plt.figure(figsize=(20, 12.5)) will increase the size of the figure window but not the graph aspect ratio itself. So, you can choose to remove this line or leave it. I removed it and got this result:

As I mentioned on my comment above, I don't know if this is what you wanted, but you can see the ticks are not aligned with each patch. So if you want them aligned you can change the np.arange() call on your plt.yticks() call to something like this:

plt.yticks(np.arange(-0.5, 5.5), [utilities.num2pid[k] for k in range(5)])

Output:

Hope this helps.

这篇关于Matplotlib图形大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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