我想用ggplot绘制在条形图中掷骰子的结果。
import numpy
import ggplot
import pandas
frame = pandas.DataFrame()
for i in range(6):
frame.loc[i, 'pips'] = i+1
rand = numpy.random.random_integers(1, 6, 100)
for i in range(len(count)):
frame.loc[i, 'events'] = numpy.sum(rand == i+1)
frame['propability'] = frame.events / frame.events.sum()
ggplot.ggplot(ggplot.aes(x='pips', weight='events'), frame) + ggplot.geom_bar()
结果为
从我预期的情节示例到
如何修复这两件事?
答案 0 :(得分:2)
使用参数" binwidth","限制"和"休息"像这样:
ggplot.ggplot(ggplot.aes(x='pips', weight='events'), frame) +
ggplot.geom_bar(binwidth=1) +
ggplot.scale_x_continuous(limits = (1,6), breaks = range(1,7))
这给了我: