如何创建在一定范围内开始和结束的条形图 [英] How do I create a bar chart that starts and ends in a certain range
问题描述
我创建了一个计算机模型(只是为了好玩)来预测足球比赛的结果.我运行了一个计算机模拟来预测一个团队将获得多少分.我得到了每个团队的模拟结果列表.
我想绘制类似置信区间的图形,但要使用条形图.
我考虑了以下选项:
- 我考虑过使用matplotlib的烛台,但这不是外汇价格.
- 我也考虑过使用matplotlib的错误栏,特别是因为事实证明我可以将图形栏+错误栏混搭,但这并不是我真正想要的.实际上,我的目标是Nate Silver的538次选举预测结果.
Nate Silver 的太复杂了,他对分布进行了着色并改变了百分比的大小.我只想要一个在特定范围内绘制的简单条形图.
我不想诉诸于如
I created a computer model (just for fun) to predict soccer match result. I ran a computer simulation to predict how many points that a team will gain. I get a list of simulation result for each team.
I want to plot something like confidence interval, but using bar chart.
I considered the following option:
- I considered using matplotlib's candlestick, but this is not Forex price.
- I also considered using matplotlib's errorbar, especially since it turns out I can mashes graphbar + errorbar, but it's not really what I am aiming for. I am actually aiming for something like Nate Silver's 538 election prediction result.
Nate Silver's is too complex, he colored the distribution and vary the size of the percentage. I just want a simple bar chart that plots on a certain range.
I don't want to resort to plot bar stacking like shown here
Matplotlib's barh
(or bar
) is probably suitable for this:
import numpy as np
import matplotlib.pylab as pl
x_mean = np.array([1, 3, 6 ])
x_std = np.array([0.3, 1, 0.7])
y = np.array([0, 1, 2 ])
pl.figure()
pl.barh(y, width=2*x_std, left=x_mean-x_std)
The bars have a horizontal width of 2*x_std
and start at x_mean-x_std
, so the center denotes the mean value.
It's not very pretty (yet), but highly customizable:
这篇关于如何创建在一定范围内开始和结束的条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!