2013-03-08 1 views
5

, मैं निम्नलिखित साजिश का उत्पादन करने प्रबंधित किया है पर और टिक के बीच के अंतर के बावजूद, प्रत्येक पैमाने में y-max मान प्रस्तुत करने वाला एक टिक जोड़ें। ऐसी साजिश का एक उदाहरण नीचे प्रस्तुत किया गया है। यह तब उत्पन्न होता है जब वाई-मैक्स टिकिंग अंतराल का एक बहु होता है।matplotlib एक विशिष्ट टिक अक्ष अधिकतम पेश जोड़ने अवलोकन प्रति कई तराजू के लिए क्रमश: टिप्पणियों प्लॉट करने के लिए कोशिश कर रहा है कई तराजू प्रेक्षण

enter image description here

धन्यवाद, एफ

यहाँ इन उदाहरण का उत्पादन किया जाता कोड है।

import numpy as np 
import pylab as pl 
import matplotlib as plt 
import matplotlib.ticker as ticker 
import matplotlib.transforms 

def add_scales(fig, axes, scales, subplot_reduction_factor=0.1, margin_size=50): 
    nb_scales = len(scales) 
    b,l,w,h = zoom_ax.get_position().bounds 

    _, ymax = axes.get_ylim() 

    # Saves some space to the right so that we can add our scales 
    fig.subplots_adjust(right=1-(subplot_reduction_factor)*nb_scales) 

    for (n, (vmin, vmax, color, label, alignment)) in enumerate(scales): 

     # Adjust wrt. the orignial figure's scale 
     nax = fig_zoom.add_axes((b,l,w,(h * alignment)/ymax)) 
     nax.spines['right'].set_position(('outward', -40+n*margin_size)) 
     nax.set_ylim((vmin,vmax)) 

     # Move ticks and label to the right 
     nax.yaxis.set_label_position('right') 
     nax.yaxis.set_ticks_position('right') 

     # Hides everything except yaxis 
     nax.patch.set_visible(False) 
     nax.xaxis.set_visible(False) 
     nax.yaxis.set_visible(True) 
     nax.spines["top"].set_visible(False) 
     nax.spines["bottom"].set_visible(False) 

     # Color stuff 
     nax.spines['right'].set_color(color) 
     nax.tick_params(axis='y', colors=color) 
     nax.yaxis.set_smart_bounds(False) 
     #nax.yaxis.label.set_color(color) 

     if label != None: 
      nax.set_ylabel(None) 

if __name__ == '__main__': 

    a=(np.random.normal(10,5,100)) 

    a=np.linspace(0,100,100) 
    c=np.linspace(0,80, 100) 
    d=np.linspace(0,40,100) 


    fig_zoom = plt.pyplot.figure() 
    zoom_ax = fig_zoom.add_subplot(1,1,1) 


    zoom_ax.plot(a,c) 
    zoom_ax.plot(a,d) 
    zoom_ax.set_title('Zoom') 
    zoom_ax.set_xlabel('A') 
    zoom_ax.set_ylabel('B') 
    zoom_ax.set_ylim((0,100)) 
    zoom_ax.grid() 
    add_scales(fig_zoom, 
       zoom_ax, [(0,.55,'green',None,40), 
          (0,.85,'blue',None,80)]) 

    fig_zoom.savefig(open('./test.svg','w'),format='svg') 

उत्तर

4

आप अपने अधिकतम अधिकतम उच्चतम मूल्य निर्धारित कर सकते हैं। यदि दूसरा उच्चतम यॉटिक मूल्य और आपका अधिकतम बहुत करीब है, तो लेबल अव्यवस्थित हो सकते हैं।

अपने पाश को यह जोड़ने का प्रयास करें:

tcks = nax.get_yticks() 
tcks[-1] = vmax 
nax.set_yticks(tcks) 

enter image description here

+0

यह पूरी तरह से काम करता है, बहुत धन्यवाद। –

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