在绘制子图时如何修复'numpy.ndarray'对象没有属性'get_figure'

在绘制子图时如何修复'numpy.ndarray'对象没有属性'get_figure',第1张

绘制子图时如何修复'numpy.ndarray'对象没有属性'get_figure'
  • 问题是

    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
    import numpy as np

    sinusoidal sample data

    sample_length = range(1, 6+1)
    rads = np.arange(0, 2np.pi, 0.01)
    data = np.array([np.sin(t
    rads) 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])

    crate the figure and axes

    fig, axes = plt.subplots(2, 3, figsize=(24, 10))

    unpack all the axes subplots

    axe = axes.ravel()

    assign the plot to each subplot in axe

    for i, c in enumerate(df.columns):
    df[c].plot(ax=axe[i])



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5617263.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存