Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将`GridSpec()`与`subplot()一起使用`_Python_Python 2.7_Matplotlib - Fatal编程技术网

Python 如何将`GridSpec()`与`subplot()一起使用`

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

有几篇()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)
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()