Python 如何将`GridSpec()`与`subplot()一起使用`
有几篇()SO文章介绍了如何将Python 如何将`GridSpec()`与`subplot()一起使用`,python,python-2.7,matplotlib,Python,Python 2.7,Matplotlib,有几篇()SO文章介绍了如何将GridSpec与子绘图一起使用。 我试图实现的是,允许将GridSpec与subplot一起使用,类似这样,我可以用一些循环控制的索引替换实际数组和列表索引: gs = gridspec.GridSpec(4, 1, height_ratios=[2, 2, 1, 1]) tPlot, axes = plt.subplots(4, sharex=True, sharey=False) tPlot.suptitle(node, fontsize=20
GridSpec
与子绘图一起使用。
我试图实现的是,允许将GridSpec
与subplot
一起使用,类似这样,我可以用一些循环控制的索引替换实际数组和列表索引:
gs = gridspec.GridSpec(4, 1, height_ratios=[2, 2, 1, 1])
tPlot, axes = plt.subplots(4, sharex=True, sharey=False)
tPlot.suptitle(node, fontsize=20)
axes[0].plot(targetDay[0], gs[0])
axes[1].plot(targetDay[1], gs[1])
axes[2].scatter(targetDay[2], gs[2])
axes[3].plot(targetDay[3], gs[3])
不用说,这段代码不起作用,它只是一个例子。您可以使用
gridspec\u kw
参数从子批调用中将kwargs
发送到gridspec
,而不是在子批调用之前调用gridspec.gridspec
。从:
gridspec\u kw
:dict
Dict,关键字传递给GridSpec构造函数,用于创建子地块所在的网格
例如:
import matplotlib.pyplot as plt
tPlot, axes = plt.subplots(
nrows=4, ncols=1, sharex=True, sharey=False,
gridspec_kw={'height_ratios':[2,2,1,1]}
)
tPlot.suptitle('node', fontsize=20)
axes[0].plot(range(10),'ro-')
axes[1].plot(range(10),'bo-')
axes[2].plot(range(10),'go-')
axes[3].plot(range(10),'mo-')
plt.show()