【问题标题】:Spyder IDE not displaying inline graphs using MatplotlibSpyder IDE 不使用 Matplotlib 显示内联图
【发布时间】:2020-10-22 10:43:21
【问题描述】:

我似乎无法让 spyder/matplotlib 显示内联图。数据框是具有索引、分类变量列和数值变量列的简单数据框。我想显示的图只是一个简单的降序条形图。

代码:

bar_plot2 = retailerDF.plot(kind='bar')
bar_plot2.show()

错误:

AttributeError: 'AxesSubplot' object has no attribute 'show'

我尝试了多种不同的故障排除方法,但似乎都没有奏效。我已经多次切换和更改了 spyder 中的内联设置,当然我也搜索了错误代码,但我尝试过的方法都没有奏效。

寻找正确方向的指针。提前致谢。

【问题讨论】:

  • type(bar_plot2 ) 产生了什么?这可能是一个错误的对象

标签: python matplotlib spyder


【解决方案1】:

type(bar_plot2) 产生什么?这可能是一个错误的对象!

要呈现图形,您不需要使用该变量来调用show() 方法。单独拨打.plot() 就足够了。

import matplotlib.pyplot as plt
import pandas as pd

# a simple line plot
df.plot(kind='bar')

# the plot gets saved to 'output.png'
plt.savefig('output.png')

你可以从这里看到很好的例子 - Plot column values as bar plot

【讨论】:

    猜你喜欢
    • 2015-06-04
    • 2016-02-24
    • 2016-05-19
    • 1970-01-01
    • 2020-07-03
    • 2014-07-23
    • 2019-02-06
    • 2016-02-28
    • 2019-12-15
    相关资源
    最近更新 更多