點數圖我試圖做一個point and figure chart。我可以讓它在終端上打印出來,但我想用matplotlib來繪製它。做這種事情的最佳方式是什麼?我在想分散,但是當我這樣做的時候,柱子分散得太過分了。我希望從我提供的鏈接中獲得更像列表的圖表,儘可能地使列彼此儘可能接近。有我可以覆蓋強制這個參數嗎?第一次使用matplotlib所以請原諒,如果這是微不足道的。謝謝。與matplotlib
6
A
回答
11
您可以通過選擇s
parameter調整散點圖中使用的符號的大小。您還可能需要調整你的身材(與figsize)的規模大小或軸的尺寸(與add_axes)。這是因爲散點符號是正方形的,以顯示單位表示,並且x軸和y軸不會自動調整,因此width-of-one-change = height-of-one-box。
換句話說,你提供的例子中是一個矩形圖與高度>寬度,高度和寬度被選擇爲使得寬度的酮變化==高度的酮框。
下面是應用這些技術的例子:
import matplotlib.pyplot as plt
BOX = 5
START = 365
changes = (8, -3, 4, -4, 12, -3, 7, -3, 5, -9, 3)
# one way to force dimensions is to set the figure size:
fig = plt.figure(figsize=(5, 10))
# another way is to control the axes dimensions
# for axes to have specific dimensions:
# [ x0, y0, w, h] in figure units, from 0 to 1
#ax = fig.add_axes([.15, .15, .7*.5, .7])
ax = fig.add_axes([.15, .15, .7, .7])
def sign(val):
return val/abs(val)
pointChanges = []
for chg in changes:
pointChanges += [sign(chg)] * abs(chg)
symbol = {-1:'o',
1:'x'}
chgStart = START
for ichg, chg in enumerate(changes):
x = [ichg+1] * abs(chg)
y = [chgStart + i * BOX * sign(chg) for i in range(abs(chg))]
chgStart += BOX * sign(chg) * (abs(chg)-2)
ax.scatter(x, y,
marker=symbol[sign(chg)],
s=175) #<----- control size of scatter symbol
ax.set_xlim(0, len(changes)+1)
fig.savefig('pointandfigure.png')
plt.show()
每個散點圖開發的方法非常的hackish,但關鍵的一點是,我需要與分散s
參數和數字大小來打得到想要的效果。
產生的情節是:
理想情況下,就會使散射法爲藍本的自定義方法。它會創建一個包含x,o和月份標籤的自定義Collection
instance。它也會a)自動調整軸/圖形方面或b)製作不對稱符號。這顯然是一種高級選項,專爲希望爲Matplotlib項目作爲開發人員貢獻力量的人而設計。
0
沒有親身經歷,但也許set_view_interval()或set_data_interval()從here?我已經使用Matplotlib進行了一個項目,但不必修改x軸寬度。
+0
如果你在數據框中有X和O,你會怎麼做出同樣的圖形? – 2018-02-27 04:28:00
相關問題
- 1. 與matplotlib
- 2. 與matplotlib
- 3. 與Matplotlib
- 4. 與matplotlib
- 5. 與matplotlib
- 6. 與Matplotlib
- 7. 與matplotlib
- 8. 與matplotlib
- 9. 與Matplotlib
- 10. 錯誤與matplotlib
- 11. 映射與matplotlib
- 12. 繪製與matplotlib
- 13. 日期與matplotlib
- 14. IndexError與matplotlib
- 15. 繪製與Matplotlib
- 16. 情節與matplotlib
- 17. 與OO Matplotlib
- 18. 磚牆與matplotlib
- 19. Matplotlib與PyQt5
- 20. 產生與matplotlib
- 21. 請與matplotlib
- 22. 問題與matplotlib
- 23. 與matplotlib GridSpec
- 24. plt.figure()與在Matplotlib
- 25. 繪製與matplotlib
- 26. Tkinter的與matplotlib
- 27. 條形圖與Matplotlib
- 28. 頻率圖與matplotlib
- 29. 獲取PySide與matplotlib
- 30. 直方圖與matplotlib
如果傑夫是聽在這裏,你說你已經成功地印在終端的P&F圖。你願意嗎?共享Python代碼(或至少是邏輯)?我正在嘗試在Python中開發P&F圖表。如果可以在終端打印出來,我會嘗試將其轉換爲HTML格式。謝謝, – Vineet 2012-08-17 09:39:59
你有沒有得到一個工作點和數字圖表繪製。 – 2018-02-27 04:28:58