简体   繁体   中英

Set the color of the ticker powerlimits using matplotlib

I used the following code to set the power label on the y-axis of my plot to be [1e-3]. (Meaning that all my y-tick values are multiplied by 1e-3).

ax1 = plt.gca()
y_formatter = mpl.ticker.ScalarFormatter(useOffset=True)
y_formatter.set_powerlimits((-3,5))
ax1.yaxis.set_major_formatter(y_formatter)

In addition I want to color all my ticklabels and axis label blue because I am using a twin axis plot.

ax1.set_ylabel('absorpitivity (cm$^{-1}$)',color='b')
for t1 in ax1.get_yticklabels():
    t1.set_color('b')

This yields a plot where all my y-tick labels and axis label are blue but the power label at the top of the axis that sets the overall scale is still black. How can I also set the power label at the top of the y-axis to be blue also?

I'd really like to post a picture of my plot, but I don't have enough reputation points to post an image. If this gets up-voted and I get some points I'll edit the post to upload the picture.

You can access it by using

ax1.yaxis.get_offset_text().set_color('b')

For future reference, and if you haven't tried already, you can find these sort of properties by using the ipython interpreter. Using the tab-completion from the ax1 instance you can see a list of methods to access. From here its some guess work but it might help you in future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM