के बीच दूरी (मिमी/सेमी/अंक ... में) कैसे सेट करें मैं लंबे समय से इंटरनेट पर देख रहा हूं लेकिन इसे समझने के तरीके को समझ नहीं पाया। मुझे कई आंकड़े आकर्षित करने की ज़रूरत है जिनके xticks को numpy.arange (1, N) के रूप में परिभाषित किया गया है, एन प्रत्येक आकृति के लिए अलग है। मैं चाहता हूं कि xticks के बीच की दूरी सभी आंकड़ों (जैसे 1 सेमी) पर समान हो, यानी, प्रत्येक आकृति की चौड़ाई numpy.arange (1, N) के आकार पर निर्भर होनी चाहिए। ऐसा करने का कोई विचार क्या है?Matplotlib - xticks
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')
यह प्रत्येक टिक के बीच 1 सेमी अंतरिक्ष के साथ 10 सेमी की एक xaxis साथ 11.8 सेमी की एक आकृति में परिणाम
संबंधित मुद्दे
- 1. matplotlib xticks लेबल ओवरलैप
- 2. matplotlib
- 3. हिस्टोग्राम matplotlib
- 4. matplotlib
- 5. घुमावदार xticklabels को उनके संबंधित xticks
- 6. matplotlib
- 7. matplotlib
- 8. matplotlib
- 9. matplotlib
- 10. Matplotlib
- 11. matplotlib
- 12. matplotlib
- 13. matplotlib
- 14. matplotlib
- 15. matplotlib
- 16. matplotlib
- 17. matplotlib
- 18. matplotlib
- 19. matplotlib
- 20. matplotlib
- 21. MatPlotLib
- 22. Matplotlib
- 23. matplotlib?
- 24. matplotlib
- 25. matplotlib
- 26. matplotlib
- 27. matplotlib
- 28. matplotlib
- 29. matplotlib
- 30. matplotlib