【问题标题】:box plot not appearing in Google Colab箱线图未出现在 Google Colab 中
【发布时间】:2020-06-07 14:06:30
【问题描述】:

尝试使用 Google Colab 为我的 Intro Python 课程创建一个简单的箱线图。它不像我想要的那样出现。您可以在下面看到我的代码和输出。我阅读了一份关于 NBA 统计数据的文件,我的箱线图将基于一个名为“SHOT_CLOCK”的变量。

到目前为止我所拥有的:

import pandas as pd
from matplotlib import pyplot as plt

df = pd.read_csv('file path')

plt.boxplot(df['SHOT_CLOCK'], vert=False)
plt.title('Box Plot for SHOT_CLOCK')
plt.xlabel('Shot Clock')
plt.show()

输出:

【问题讨论】:

    标签: python pandas matplotlib boxplot


    【解决方案1】:

    编辑 在您的示例中,您正在传递一个 Series 对象,请尝试这种方式

    plt.figure()
    plt.title('Box Plot for SHOT_CLOCK')
    plt.xlabel('Shot Clock')
    df.boxplot(column='SHOT_CLOCK')
    

    【讨论】:

      【解决方案2】:

      将以下 Import 添加到您的代码后,它将起作用:

      import matplotlib.pyplot as plt
      plt.style.use('classic')
      %matplotlib inline
      

      【讨论】:

      • 通常解释对提问者有帮助,谢谢。
      猜你喜欢
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 2022-06-29
      • 2020-09-06
      • 2013-09-07
      • 1970-01-01
      • 2019-06-19
      • 2021-07-07
      相关资源
      最近更新 更多