【问题标题】:Plotting graph using matplotlib in Jupyter iPython Notebook在 Jupyter iPython Notebook 中使用 matplotlib 绘制图形
【发布时间】:2017-08-08 05:40:06
【问题描述】:

我正在尝试在 Jupyter python notebook 中使用 matplotlib 绘制图形。但是当我分配 y 轴标签时,它没有显示在图表中,并且它正在绘制两个图表。我使用的代码是:

trans_count_month = df.groupby('month_').TR_AMOUNT.count() 
plt.xlabel('Months')  #X-axis label
plt.ylabel('Total Transactions Count') #Y-axis label 
plt.title("Month wise Total Transaction Count") #Chart title. 
width = 9
height = 5
plt.figure(figsize=(width, height))
trans_count_month.plot(kind='bar')
plt.figure(figsize=(width, height))

我得到的输出是:

如何只显示一个带有 y 轴标签的图,如果有任何其他方法可以绘制此图,请分享解决方案。

【问题讨论】:

  • 我猜只是删除第一个plt.figure(figsize=width, height))
  • 尝试更改顺序。 plt.xlabel/ylable/title 应该在 .plot 之后。此外,使用plotfigsize 关键字参数代替plt.figure(figsize=())
  • 感谢@Dror,它现在可以正常工作了

标签: python matplotlib plot


【解决方案1】:

这是一个最小的例子:

将熊猫导入为 pd

%matplotlib inline
from matplotlib import pyplot as plt
import pandas as pd

s = pd.Series([1,2,3], index=['a','b','c'])

s.plot.bar(figsize=(20,10))
plt.xlabel('Foo')
plt.ylabel('Bar')
plt.title("Hello World");

哪个更好地利用 pandas 和 matplotlib。

【讨论】:

    猜你喜欢
    • 2017-02-01
    • 1970-01-01
    • 2017-07-07
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 2018-01-06
    • 2013-03-06
    • 1970-01-01
    相关资源
    最近更新 更多