
问题是
plt.subplots(2, 3, figsize=(24, 10))
创建两组3个子图,而不是一组6个子图。array([[, , ],
[, , ]], dtype=object)打开所有插曲阵列的
axes
使用axes.ravel()
。numpy.ravel
,它返回一个展平的数组。- 列表理解也可以,
axe = [sub for x in axes for sub in x]
- 将每个图分配给中的一个子图
axe
。 如何解决AttributeError:当绘制子图时,“ numpy.ndarray”对象没有属性“ get_figure”是一个类似的问题。
import pandas as pd
sinusoidal sample data
import numpy as npsample_length = range(1, 6+1)
crate the figure and axes
rads = np.arange(0, 2np.pi, 0.01)
data = np.array([np.sin(trads) for t in sample_length])
df = pd.Dataframe(data.T, index=pd.Series(rads.tolist(), name=’radians’), columns=[f’freq: {i}x’ for i in sample_length])fig, axes = plt.subplots(2, 3, figsize=(24, 10))
unpack all the axes subplotsaxe = axes.ravel()
assign the plot to each subplot in axefor i, c in enumerate(df.columns):
df[c].plot(ax=axe[i])
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)