python - Set the color of y axis coefficient in matplotlib -


this python code:

import matplotlib.pyplot plt import numpy np  # create data data = np.random.randn(200, 2) data = data * 1e20 assert(data.ndim == 2) assert(data.shape[1] == 2) x = np.arange(data.shape[0]) fix, ax1 = plt.subplots() ax1.plot(x, data[:, 0], 'b') in ax1.get_yticklabels():     i.set_color('b') ax1.set_ylabel('', color='b') ax2 = ax1.twinx() ax2.plot(x, data[:, 1], 'r') in ax2.get_yticklabels():     i.set_color('r') plt.show() 

i trying plot 2 curves sharing same x axis on 1 plot. want have different colors 2 y axes. result:

plot

the thing is, on left y axis, there coefficient "1e20" on top. want colored blue too. how can achieve that?

in matplotlib, coefficient referred "offset text" axis associated with. can access calling get_offset_text() method on appropriate axis object. can use various formatting methods. in case, you'll want call set_color() method on each of y axes. can accomplish adding following 2 lines of code before calling plt.show():

ax1.yaxis.get_offset_text().set_color("blue") ax2.yaxis.get_offset_text().set_color("red") 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -