python - Plot several Y axes -


i plot several y axes, different scales, here solution based on exemples found on web, creates 1 y axis, have more in data.

        fig, ax = plt.subplots()         plt.subplots_adjust(right=0.75)          x, y, c, m, l = self.mdata[0]         ax.plot(x, y, color=c)         ax.set_ylabel(l, color=c)         tl in ax.get_yticklabels():             tl.set_color(c)          ax.set_xlabel('time')          in range(1, len(self.mdata)):             ax_other = ax.twinx()             if == 1:                 offset = 0             else:                 offset = 60 * (i - 1)              ax_other.set_frame_on(true)             ax_other.patch.set_visible(false)             ax_other.yaxis.set_label_position('right')             ax_other.yaxis.set_ticks_position('right')             ax_other.spines['right'].set_position(('outward', offset))              x, y, c, m, l = self.mdata[i]             ax_other.plot(x, y, color=c)              ax_other.set_ylabel(l, color=c)             tl in ax_other.get_yticklabels():                 tl.set_color(c)          plt.gcf().autofmt_xdate() 

in code plot first set of data, if there other set plotted create new axis each set. x axis displays dates, same each set of data can have. , problem code displays 1 of axis have.

mdata list of namedtuples :

data_tuple = namedtuple('data', ['x', 'y', 'color', 'marker', 'label']) 

x list of datetime object, y list of float, color, marker , label string.

data(x=[datetime.datetime(2011, 1, 1, 0, 0, 25, 135000), datetime.datetime(2011, 2, 1, 0, 0, 57, 386000), datetime.datetime(2011, 3, 1, 0, 0, 59, 579000), datetime.datetime(2011, 4, 1, 0, 0, 27, 676000), datetime.datetime(2011, 5, 1, 0, 0, 25, 135000), datetime.datetime(2011, 6, 1, 0, 0, 26, 414000), datetime.datetime(2011, 7, 1, 0, 0, 28, 145000), datetime.datetime(2011, 8, 1, 0, 0, 26, 432000), datetime.datetime(2011, 9, 1, 0, 0, 27, 301000), datetime.datetime(2011, 10, 1, 0, 0, 27, 643000), datetime.datetime(2011, 11, 1, 0, 0, 27, 673000), datetime.datetime(2011, 12, 1, 0, 0, 28, 294000)], y=[-10.246537396121893, 1.3039215686274515, 1.007462686567164, -0.12771084337349403, -0.1932367149758454, -0.3196125907990315, -0.04128440366972498, -0.19950738916256117, -1.6319018404907975, -1.1532258064516134, -1.666666666666668, -2.3958333333333326], color='red', marker='x', label='mean') data(x=[datetime.datetime(2011, 1, 1, 0, 0, 25, 135000), datetime.datetime(2011, 2, 1, 0, 0, 57, 386000), datetime.datetime(2011, 3, 1, 0, 0, 59, 579000), datetime.datetime(2011, 4, 1, 0, 0, 27, 676000), datetime.datetime(2011, 5, 1, 0, 0, 25, 135000), datetime.datetime(2011, 6, 1, 0, 0, 26, 414000), datetime.datetime(2011, 7, 1, 0, 0, 28, 145000), datetime.datetime(2011, 8, 1, 0, 0, 26, 432000), datetime.datetime(2011, 9, 1, 0, 0, 27, 301000), datetime.datetime(2011, 10, 1, 0, 0, 27, 643000), datetime.datetime(2011, 11, 1, 0, 0, 27, 673000), datetime.datetime(2011, 12, 1, 0, 0, 28, 294000)], y=[-8.0, 19.0, 11.0, 6.0, 6.0, 6.0, 6.0, 6.0, 2.0, 2.0, 2.0, 2.0], color='red', marker='x', label='max') data(x=[datetime.datetime(2011, 1, 1, 0, 0, 25, 135000), datetime.datetime(2011, 2, 1, 0, 0, 57, 386000), datetime.datetime(2011, 3, 1, 0, 0, 59, 579000), datetime.datetime(2011, 4, 1, 0, 0, 27, 676000), datetime.datetime(2011, 5, 1, 0, 0, 25, 135000), datetime.datetime(2011, 6, 1, 0, 0, 26, 414000), datetime.datetime(2011, 7, 1, 0, 0, 28, 145000), datetime.datetime(2011, 8, 1, 0, 0, 26, 432000), datetime.datetime(2011, 9, 1, 0, 0, 27, 301000), datetime.datetime(2011, 10, 1, 0, 0, 27, 643000), datetime.datetime(2011, 11, 1, 0, 0, 27, 673000), datetime.datetime(2011, 12, 1, 0, 0, 28, 294000)], y=[-12.0, -7.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -6.0, -7.0, -7.0], color='yellow', marker='o', label='min') 


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -