我一直在網上查找很長時間,但無法弄清楚如何製作它。我需要畫出幾個xticks被定義爲numpy.arange(1,N)的數字,N對於每個數字都不相同。我希望所有數字(例如1釐米)上的xticks之間的間距相同,也就是說,每個數字的寬度必須取決於numpy.arange(1,N)的大小。任何想法如何做到這一點?Matplotlib - 如何設置xticks之間的距離(以mm/cm /點爲單位)
6
A
回答
2
我認爲你可以通過仔細控制你的座標軸大小(作爲圖的一部分),ax.set_xlim
和fig.set_size_inches
(doc)的組合來設置圖的實際大小。
前
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.set_xlim([0,N])
fig.set_size_inches([N/2.54,h])
0
要在@ tcaswell的答案擴大,這裏是我如何做到這一點時,我想微觀管理我的軸和刻度間距離的實際尺寸。
import numpy as np
import matplotlib.pyplot as plt
plt.close('all')
#------------------------------------------------------ define xticks setup ----
xticks_pos = np.arange(11) # xticks relative position in xaxis
N = np.max(xticks_pos) - np.min(xticks_pos) # numbers of space between ticks
dx = 1/2.54 # fixed space between xticks in inches
xaxis_length = N * dx
#------------------------------------------------------------ create figure ----
#---- define margins size in inches ----
left_margin = 0.5
right_margin = 0.2
bottom_margin = 0.5
top_margin = 0.25
#--- calculate total figure size in inches ----
fwidth = left_margin + right_margin + xaxis_length
fheight = 3
fig = plt.figure(figsize=(fwidth, fheight))
fig.patch.set_facecolor('white')
#---------------------------------------------------------------- create axe----
#---- axes relative size ----
axw = 1 - (left_margin + right_margin)/fwidth
axh = 1 - (bottom_margin + top_margin)/fheight
x0 = left_margin/fwidth
y0 = bottom_margin/fheight
ax0 = fig.add_axes([x0, y0, axw, axh], frameon=True)
#---------------------------------------------------------------- set xticks----
ax0.set_xticks(xticks_pos)
plt.show(block=False)
fig.savefig('axis_ticks_cm.png')
這導致11.8釐米10釐米的x軸的圖與每個蜱之間1釐米空間:
相關問題
- 1. 設置gridspec中ticks之間的距離
- 2. 如何測量兩個CLLococ之間的距離(單位爲米)?
- 3. 兩個GEO位置之間的距離
- 4. Postgis中的2個點之間的距離以4326米爲單位
- 5. 如何計算點之間的距離?
- 6. graphviz/dot:兩個節點之間的距離是否可以單獨設置?
- 7. 如何設置mkmapview以顯示距離我當前位置100米的距離?
- 8. 點之間的距離
- 9. 如何獲得距離眩暈兩點之間的距離
- 10. matplotlib twinx在特定位置的xticks
- 11. 在jQuery中爲長距離短距離設置動畫位置
- 12. 一個點和幾個位置之間的距離
- 13. 找到2個經緯度點之間的距離(單位:米)
- 14. 計算兩點之間的距離(單位:米)
- 15. Android之間的幾個位置之間的距離
- 16. 從iphone設置更改距離單位
- 17. 在xticks之間設置標籤
- 18. 如何查找兩個經度位置之間的距離?
- 19. 如何顯示地圖上兩個位置之間的距離?
- 20. Three.js - 如何計算兩個3D位置之間的距離?
- 21. 如何找到位置之間的距離
- 22. 我該如何計算兩個位置之間的距離
- 23. 使用Seaborn設置軸標籤之間的距離
- 24. 如何強制設置我的div之間的距離?
- 25. 如何設置垂直排列的元素之間的距離?
- 26. Matlab GPS +以米爲單位的距離
- 27. 通過兩點之間的距離設置區域
- 28. 計算用戶位置和固定位置之間的距離
- 29. 如何獲得我的當前位置和新位置之間的距離?
- 30. 滾動ListView laggy因爲計算位置之間的距離