bglstat = np.array([9.0, 10.0, 2.0, 7.0, 7.0, 4.0])
candyn = np.array([2.0, 2.0, 1.0, 1.0, 1.0, 3.0, 1.0, 2.0, 1.0, 1.0])
candid = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
fig = plt.figure()
a2 = fig.add_subplot(111)
a2.scatter(candid, candyn, color='red')
a2.set_xlabel("Candidate Bulgeless Galaxy ID #")
a2.set_ylabel("Classified as Bulgeless")
a2.set_xticks([1,2,3,4,5,6,7,8,9,10])
a2.hist(candyn, bins = arange(-.5,10.5,1))
plt.show()
給出:
所以,很顯然,答案是 「是」。現在需要根據您的需要調整直方圖特徵。在上面的示例中,它使用與散點數據相同的X和Y比例,但不一定如此。
或者您是否正在尋找一種方法來製作直方圖數據的條形圖?然後:
bglstat = np.array([9.0, 10.0, 2.0, 7.0, 7.0, 4.0])
candyn = np.array([2.0, 2.0, 1.0, 1.0, 1.0, 3.0, 1.0, 2.0, 1.0, 1.0])
candid = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
fig = plt.figure()
a2 = fig.add_subplot(111)
a2.bar(candid-.8/2, candyn, width=.8)
a2.set_xlabel("Candidate Bulgeless Galaxy ID #")
a2.set_ylabel("Classified as Bulgeless")
a2.set_xticks([1,2,3,4,5,6,7,8,9,10])
plt.show()
順便說一句,在set_xticks
看起來有點奇怪。您可以考慮使用set_xticks(candid)
來顯示您的類別,或者使用set_xticks(np.arange(1,11))
來明確設置滴答1..10。此外,我建議你添加一些代碼來設置範圍(例如a2.set_xlim(-1,11)
,a2.set_ylim(0, np.max(candyn) + 1)
)以獲得對縮放的控制(經驗法則:如果您手動設置刻度,則還應該手動設置範圍。)
你現在我意識到我需要一個條形圖而不是直方圖 – user1821176
有時候解決方法比想象的簡單得多:) – DrV