![](/img/trans.png)
[英]Plotting an array in histogram style without using hist function in Python with Matplotlib
[英]Python: Plotting Histogram with hist() and specifying y axis
您好,目前在繪制直方圖時遇到麻煩,我得到了此圖像http://imgur.com/a/yijpT ,我想將y值更改為
y = [0.125, 0.21875, 0.25, 0.1875, 0.0625, 0.1875, ...]
我目前遇到的困難是這樣做
numbins = range(32)
plt.title('Probabiliy of Heads from 32 Coin Tosses')
plt.xlabel('% heads')
plt.ylabel('relative frequency')
plt.hist(x,numbins,alpha=.2)
plt.show()
其中x是我擁有的x值。 我將x和y保存為數組,這樣
x = [array of numbers]
y = [array of numbers]
我試過了
plt.hist(x,y,alpha=.2)
但這不起作用。 我不確定如何更改此設置,我嘗試在網上尋找解決方案,但找不到我要找的東西。 任何幫助,將不勝感激!
plt.hist()
創建數據的直方圖。 您已經有了直方圖,因此只需使用plt.plot(x, y, drawstyle='steps-mid')
。
我認為您正在尋找條形圖請嘗試以下代碼塊:
import random
import matplotlib.pyplot as plt
x = range(32)
y=[random.uniform(0,1) for p in range(32)]
plt.bar(x,y,align='center') # A bar chart
plt.title('Probabiliy of Heads from 32 Coin Tosses')
plt.xlabel('% heads')
plt.ylabel('Relative Frequency')
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.