其实很简单,就是算了一下百分比权重,乘以了一个权重值

import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
from numpy.random import randn
from matplotlib.font_manager import FontProperties
def to_percent(y,position):
    return str(100*y)+"%"#这里可以用round()函数设置取几位小数

font=FontProperties(fname='/Library/Fonts/Songti.ttc')#这里设置字体,可以显示中文
x=randn(1000)
plt.hist(x,bins=30,weights=[1./len(x)]*len(x))#这里weights是每一个数据的权重,这里设置是1,weights是和x等维的列表或者series
fomatter=FuncFormatter(to_percent)
plt.gca().yaxis.set_major_formatter(fomatter)

plt.title("频率分布直方图")
plt.show()

相关文章:

  • 2021-11-17
  • 2021-09-13
  • 2022-12-23
  • 2021-05-31
  • 2021-05-05
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-20
  • 2022-12-23
  • 2022-03-02
  • 2022-12-23
  • 2021-11-27
  • 2021-06-21
  • 2022-02-01
相关资源
相似解决方案