2012-07-22 10 views
7

मैं matlibplot axes का उपयोग करके 2 सबप्लॉट्स प्लॉट करना चाहता हूं। चूंकि इन दो सबप्लॉट्स में एक ही ylabel और ticks हैं, इसलिए मैं दूसरे उप-स्थान के दोनों टिक और अंक बंद करना चाहता हूं।मैटलबप्लॉट अक्षों की टिक और अंक कैसे बंद करें?

import matplotlib.pyplot as plt 
ax1=plt.axes([0.1,0.1,0.4,0.8]) 
ax1.plot(X1,Y1) 
ax2=plt.axes([0.5,0.1,0.4,0.8]) 
ax2.plot(X2,Y2) 

Btw, एक्स अक्ष के निशान ओवरलैप और यकीन नहीं एक स्वच्छ समाधान है या नहीं है कि क्या वहाँ: के बाद मेरी छोटी स्क्रिप्ट है। (एक समाधान अंतिम उपरोक्त को छोड़कर प्रत्येक सबप्लॉट के लिए अंतिम निशान अदृश्य हो सकता है, लेकिन यह सुनिश्चित नहीं है कि कैसे)। धन्यवाद!

उत्तर

8

एक त्वरित गूगल और मैंने पाया जवाब:

plt.setp(ax2.get_yticklabels(), visible=False) 
ax2.yaxis.set_tick_params(size=0) 
ax1.yaxis.tick_left() 
4

एक थोड़ा अलग समाधान हो सकता है वास्तव में ticklabels को '' स्थापित करने के लिए। निम्नलिखित सभी y-ticklabels से छुटकारा पाने और निशान टिक जाएगा:

# This is from @pelson's answer 
plt.setp(ax2.get_yticklabels(), visible=False) 

# This actually hides the ticklines instead of setting their size to 0 
# I can never get the size=0 setting to work, unsure why 
plt.setp(ax2.get_yticklines(),visible=False) 

# This hides the right side y-ticks on ax1, because I can never get tick_left() to work 
# yticklines alternate sides, starting on the left and going from bottom to top 
# thus, we must start with "1" for the index and select every other tickline 
plt.setp(ax1.get_yticklines()[1::2],visible=False) 

और अब पिछले tickmark और x- अक्ष

# I used a for loop only because it's shorter 
for ax in [ax1, ax2]: 
    plt.setp(ax.get_xticklabels()[-1], visible=False) 
    plt.setp(ax.get_xticklines()[-2:], visible=False) 
के लिए लेबल से छुटकारा पाने के
संबंधित मुद्दे