2011-06-07 17 views
19

क्योंकि वे साजिश क्षेत्र के अंदर खींचे जाते हैं, कई matplotlib भूखंडों में डेटा द्वारा अक्ष टिक्स अस्पष्ट होते हैं। अक्षरों बाहरी से विस्तारित टिकों को आकर्षित करने का एक बेहतर तरीका है, जैसा कि ggplot, आर की साजिश प्रणाली में डिफ़ॉल्ट है।matplotlib में, आप आर-स्टाइल अक्ष टिक्स कैसे आकर्षित करते हैं जो धुरी से बाहर की ओर इंगित करते हैं?

सिद्धांत रूप में, इस x- अक्ष और y- अक्ष के लिए TICKDOWN और TICKLEFT लाइन शैलियों के साथ टिक लाइनों पुनः बनाकर किया जा सकता है क्रमशः टिक्स:

import matplotlib.pyplot as plt 
import matplotlib.ticker as mplticker 
import matplotlib.lines as mpllines 

# Create everything, plot some data stored in `x` and `y` 
fig = plt.figure() 
ax = fig.gca() 
plt.plot(x, y) 

# Set position and labels of major and minor ticks on the y-axis 
# Ignore the details: the point is that there are both major and minor ticks 
ax.yaxis.set_major_locator(mplticker.MultipleLocator(1.0)) 
ax.yaxis.set_minor_locator(mplticker.MultipleLocator(0.5)) 

ax.xaxis.set_major_locator(mplticker.MultipleLocator(1.0)) 
ax.xaxis.set_minor_locator(mplticker.MultipleLocator(0.5)) 

# Try to set the tick markers to extend outward from the axes, R-style 
for line in ax.get_xticklines(): 
    line.set_marker(mpllines.TICKDOWN) 

for line in ax.get_yticklines(): 
    line.set_marker(mpllines.TICKLEFT) 

# In real life, we would now move the tick labels farther from the axes so our 
# outward-facing ticks don't cover them up 

plt.show() 

लेकिन व्यवहार में, कि केवल आधा है समाधान क्योंकि get_xticklines और get_yticklines विधियां केवल प्रमुख टिक लाइनें लौटती हैं। मामूली टिक अंदर की तरफ इशारा करते रहते हैं।

नाबालिग टिकों के लिए काम क्या है?

उत्तर

29

अपने matplotlib कॉन्फ़िग फ़ाइल में, matplotlibrc, आप सेट कर सकते हैं:

xtick.direction  : out  # direction: in or out 
ytick.direction  : out  # direction: in or out 

और इस आकर्षित करेगा दोनों बड़ी और छोटी टिक्स जावक डिफ़ॉल्ट रूप से, आर एक भी कार्यक्रम के लिए की तरह, बस कार्य करें:

>> from matplotlib import rcParams 
>> rcParams['xtick.direction'] = 'out' 
>> rcParams['ytick.direction'] = 'out' 
4

आपको कम से कम दो तरह से नाबालिगों प्राप्त कर सकते हैं:

>>> ax.xaxis.get_ticklines() # the majors 
<a list of 20 Line2D ticklines objects> 
>>> ax.xaxis.get_ticklines(minor=True) # the minors 
<a list of 38 Line2D ticklines objects> 
>>> ax.xaxis.get_minorticklines() 
<a list of 38 Line2D ticklines objects> 

ध्यान दें कि 38 है, क्योंकि छोटी सी टिक लाइनों भी MultipleLocator कॉल द्वारा "प्रमुख" स्थानों पर तैयार की गई है।

+0

यह ऐसा करेगा। धन्यवाद। – pash

संबंधित मुद्दे