我有一个28行×2列的子图(实际上可以改变)。第一列的所有行的yaxis比例应该是相同的(也必须适用于第二列)....
所有的xax都应该是相同的。
我想要做的是在输出图中创建一些内容,显示第一列和第二列的yaxis以及两列的xaxis ...我还希望获得一个标签第1列和第2列(说明这些数据是什么)。
我还想改变绘图的方面,以便可以更清楚地看到它(可能会增加y轴的外形尺寸并稍微减少x轴的大小)。
我想要的子图,如果没有重新调整大小,应该是这样的:
它可能是不同的东西。我真的不知道有什么可以做出我的要求。
我用于生成图形的代码(没有绘制标签):
def pltconc(conc,self):
t=self.t
idx1=0
conc=conc*1000000
c=len(find( self.ml[:,3]==1 ))
from scipy.stats import scoreatpercentile #To adjust the scales
ymin1 = max([median(scoreatpercentile(conc[:,i,:],0.05)) for i in range(28)])
ymax1 = max([median(scoreatpercentile(conc[:,i,:],99.95)) for i in range(28)])
for idx1 in range(c):
a=subplot(c,2,2*idx1+1, adjustable='box-forced')
plt.plot(t,conc[:,idx1,0],color='r')
plt.plot(t,conc[:,idx1,1],color='b')
plt.axis('tight')
xlim(0,max(self.t))
ylim(ymin1,ymax1)
frame1 = plt.gca()
a.set_yticklabels([])
a.set_xticklabels([])
ax=subplot(c,2,2*idx1+2, adjustable='box-forced')
CBV = (conc[:,idx1,2]*100)/(90+conc[:,idx1,2])
StO2 = (conc[:,idx1,0]*100)/(90+conc[:,idx1,2])
ymin2 = max(median(scoreatpercentile(CBV,0.05)),median(scoreatpercentile(StO2,0.05)))
ymax2 = max(median(scoreatpercentile(StO2,99.95)),median(scoreatpercentile(CBV,99.95)))
plt.plot(t,CBV, color='m')
plt.plot(t,StO2, color = 'b')
plt.axis('tight')
xlim(0,max(self.t))
ylim(ymin2,ymax2)
frame1 = plt.gca()
ax.set_yticklabels([])
ax.set_xticklabels([])
非常感谢您的帮助。
我改变了代码,因为我意识到它们没有正确缩放。输出数字应该有点不同,但这对于这个问题目的并不重要。
答案 0 :(得分:3)
我不完全确定你在问什么,但这就是我如何围绕这些方式绘制一些内容......
您的数字的宽高比由figsize
kwarg控制为plt.figure
(或plt.subplots
,在这种情况下)。
其他你可以明智地应用annotate
。
以下是一个例子:
import matplotlib.pyplot as plt
import numpy as np
# Generate the data
data = (np.random.random((20, 2, 2, 1001)) - 0.5).cumsum(axis=-1)
# Set up the figure (the figsize is what's going to control your aspect ratio)
fig, axes = plt.subplots(nrows=20, ncols=2, sharex=True, figsize=(6, 10))
fig.subplots_adjust(wspace=0.1, hspace=0, bottom=0.05)
# Turn off tick labels everywhere
for ax in axes.flat:
for axis in [ax.xaxis, ax.yaxis]:
axis.set_ticklabels([])
# Plot the data
color = {(0,0):'red', (0,1):'green', (1,0):'blue', (1,1):'magenta'}
for (i,j), ax in np.ndenumerate(axes):
for k in range(2):
ax.plot(data[i,j,k,:], color=color[(j,k)])
# Add stacked titles (and text legends)
titles = [['TITLE:', 'Red: Data X', 'Green: Data Y'],
['TITLE:', 'Blue: Data W', 'Magenta: Data Z']]
for i, title in enumerate(titles):
for text, ypos in zip(title, [35, 20, 5]):
axes[0,i].annotate(text, xy=(0.05, 1.0), xytext=(0, ypos), va='bottom',
xycoords='axes fraction', textcoords='offset points')
# Add arrows on "super-Y" axes
xpos, length = -0.1, 5
axes[12,0].annotate('', xy=(xpos, 0), xytext=(xpos, length),
xycoords='axes fraction', textcoords='axes fraction',
arrowprops=dict(arrowstyle='<|-'))
axes[12,0].annotate('{0} subplots'.format(length), xy=(xpos, length/2.0),
xycoords='axes fraction', rotation=90, va='center', ha='right')
# Add arrows on "super-X" axes
ypos, length = -0.7, 1000
axes[-1,0].annotate('', xy=(0, ypos), xytext=(length, ypos),
xycoords=('data', 'axes fraction'), textcoords=('data', 'axes fraction'),
arrowprops=dict(arrowstyle='<|-'))
axes[-1,0].annotate('{0} data units'.format(length), xy=(length/2.0, ypos),
xytext=(0, 5), xycoords=('data', 'axes fraction'),
textcoords='offset points', ha='center', va='bottom')
plt.show()