如何在不根据原始数据进行计算的情况下绘制宽度不相等的直方图? [英] How to plot a histogram with unequal widths without computing it from raw data?

查看:87
本文介绍了如何在不根据原始数据进行计算的情况下绘制宽度不相等的直方图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Matplotlib的 hist 说:计算并绘制直方图x".我想制作一个图,先计算任何东西.我有一个bin宽度(不相等),以及每个bin中的总量,我想绘制一个频率量直方图.

Matplotlib's hist says "Compute and draw the histogram of x". I'd like to make a plot without computing anything first. I have the bin widths (unequal), and the total amount in each bin, and I want to plot a frequency-quantity histogram.

例如,带有数据

cm      Frequency
65-75   2
75-80   7
80-90   21
90-105  15
105-110 12

它应该绘制如下图:

http://www.gcsemathstutor.com/histograms.php

其中块的面积代表每个类别中的频率.

where the area of the blocks represents the frequency in each class.

推荐答案

与David Zwicker相同:

Working on the same as David Zwicker:

import numpy as np
import matplotlib.pyplot as plt

freqs = np.array([2, 7, 21, 15, 12])
bins = np.array([65, 75, 80, 90, 105, 110])
widths = bins[1:] - bins[:-1]
heights = freqs.astype(np.float)/widths
    
plt.fill_between(bins.repeat(2)[1:-1], heights.repeat(2), facecolor='steelblue')
plt.show()

这篇关于如何在不根据原始数据进行计算的情况下绘制宽度不相等的直方图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆