我的数字包含figsize=(10,10)的维数和其中的一个子图。如何定义子图的维数为8英寸Wx8英寸H考虑到它所显示的子图的数据范围?
编辑:我之所以要搜索这个,是因为我试图创建一些发布的情节。因此,我需要我的情节有一个固定的宽度和高度,以便能够插入到手稿无缝。
下面是条形代码:
map_size = [8,8]
fig, ax = plt.subplots(1,1,figsize=map_size)
ax.plot(data)
fig.savefig('img.png', dpi=300,) # figure is the desired size, subplot seems to be scaled to fit to fig发布于 2015-05-28 08:38:25
一种选择是使用fig.subplots_adjust来设置图中子图的大小。参数left、right、bottom和top是小数单位(图的总维数)。因此,对于10x10图形中的8x8子图、right - left = 0.8等:
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(10.,10.))
fig.subplots_adjust(left=0.1,right=0.9,bottom=0.1,top=0.9)
ax=fig.add_subplot(111)这样做,如果更改图形大小,则必须手动更改左边、右侧、底部和顶部的值。
我想你可以在你的代码中建立这样的计算:
import matplotlib.pyplot as plt
subplotsize=[8.,8.]
figuresize=[10.,10.]
left = 0.5*(1.-subplotsize[0]/figuresize[0])
right = 1.-left
bottom = 0.5*(1.-subplotsize[1]/figuresize[1])
top = 1.-bottom
fig=plt.figure(figsize=(figuresize[0],figuresize[1]))
fig.subplots_adjust(left=left,right=right,bottom=bottom,top=top)
ax=fig.add_subplot(111)https://stackoverflow.com/questions/30500171
复制相似问题