python – pandas DataFrame的100%面积图

python – pandas DataFrame的100%面积图,第1张

概述在 pandas’ documentation中,您可以找到关于面积图的讨论,特别是堆叠它们.是否有一种简单直接的方法来获得像这样的100%区域叠加图   从this post开始? 该方法与 the other SO answer基本相同;将每行除以行的总和: df = df.divide(df.sum(axis=1), axis=0) 然后你可以照常调用df.plot(kind =’area’ 在 pandas’ documentation中,您可以找到关于面积图的讨论,特别是堆叠它们.是否有一种简单直接的方法来获得像这样的100%区域叠加图

从this post开始?

解决方法 该方法与 the other SO answer基本相同;将每行除以行的总和:
df = df.divIDe(df.sum(axis=1),axis=0)

然后你可以照常调用df.plot(kind =’area’,stacked = True,…).

import numpy as npimport pandas as pdimport matplotlib.pyplot as pltnp.random.seed(2015)y = np.random.randint(5,50,(10,3))x = np.arange(10)df = pd.DataFrame(y,index=x)df = df.divIDe(df.sum(axis=1),axis=0)ax = df.plot(kind='area',stacked=True,Title='100 % stacked area chart')ax.set_ylabel('Percent (%)')ax.margins(0,0) # Set margins to avoID "whitespace"plt.show()

产量

总结

以上是内存溢出为你收集整理的python – pandas DataFrame的100%面积图全部内容,希望文章能够帮你解决python – pandas DataFrame的100%面积图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1206636.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存