【问题标题】:Generating new histogram within loop with scipy使用 scipy 在循环内生成新的直方图
【发布时间】:2017-03-15 10:39:45
【问题描述】:

这是我编写的用于显示数据直方图的代码:

from scipy.stats import norm  

rdd = sc.parallelize([(0,1), (0,1), (0,2), (1,2), (1,10), (1,20), (3,18), (3,18), (3,18)])
dataframe = sqlContext.createDataFrame(rdd, ["p1", "p2"])


for col in dataframe.columns :
    dataframe.toPandas()[col].plot(kind='hist', normed=True)

显示:

如何在for col..... 循环中为每一列数据生成一个新的直方图,而不是如图所示将每一列覆盖在同一数据点上?

【问题讨论】:

    标签: python scipy pyspark


    【解决方案1】:

    你每次都需要给它一个新的图形(或至少是轴):

    import matplotlib.pyplot as plt    
    
    for col in dataframe.columns:
        fig, ax = plt.subplots(1,1)
        dataframe.toPandas()[col].plot(kind='hist', normed=True, ax=ax)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-24
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多