【问题标题】:There's no 'range' parameter in series.plot.hist, but how this work?series.plot.hist 中没有“范围”参数,但这是如何工作的?
【发布时间】:2019-02-11 10:23:02
【问题描述】:

pandas.Series.plot.hist 或 pandas.Series.plot 中没有范围参数。 但是下面的代码有效。它是如何工作的?

#wnba is Dataframe, so wnba['PTS'] is series.
wnba['PTS'].plot.hist(range = (1,600), bins = 3)

【问题讨论】:

  • @Adelin 这就是为什么我还链接了 Series.plot。 Series.plot 中也没有范围。
  • 文档状态为**kwds : keywords, Options to pass to matplotlib plotting method。意思是,如果这个调用matplotlib.pyplot.hist,range 将被传递给它。

标签: python pandas matplotlib histogram


【解决方案1】:

plot.hist 接受 **kwds 因此,无论您如何称呼它(使用任何关键字 args),它都会有正确的语法。

语义上:

  1. hist 调用 self 通过传递 kind='hist' 参数,
  2. 表示self.__call__,
  3. 依次调用plot_series,通过_get_ax_layer方法建立ax层,
  4. 然后使用ax 调用_plot 和 使用kind='hist' 参数
  5. 这最终意味着将使用HistPlot 类
  6. 最终通过range=self.kwds.get('range', None)提取range kwarg

这完全是耐心地跟随面包屑的问题。

【讨论】:

    猜你喜欢
    • 2017-04-05
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    相关资源
    最近更新 更多