Problem with ticklabel

Most of my issues have been answered through previous posts, but this is such
a specific problem, that I can't find the answer anywhere. I'm new to
matplotlib and therefore learning some of the basic things. My code is:

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.pylab as plb
import matplotlib.font_manager as font_manager
import numpy as np

#Changing font at once
##font = {'family' : 'monospace',
## 'weight' : 'bold',
## 'size' : 18}
##matplotlib.rc('font', **font)

#Changing font individually
axis_font = {'fontname':'Arial', 'size':'18'}
font_path = 'C:\Windows\Fonts\Arial.ttf'
font_prop = font_manager.FontProperties(fname=font_path, size=20)

x = np.genfromtxt('test.txt',
y =
z =

fig, ax1 = plt.subplots()
ax1.errorbar(x, y, fmt = 'b-', linewidth=3.0, xerr = 0.0, yerr = z,
ax1.set_xlabel('x-values', **axis_font)
ax1.set_ylabel('linear y-values', color='b', **axis_font)
for tl in ax1.get_yticklabels():
ax1.legend(loc=2, prop=font_prop)
for label in (ax1.get_xticklabels() + ax1.get_yticklabels()):

ax2 = ax1.twinx()
y2 = np.exp(x)
ax2.errorbar(x, y2, fmt = 'r-', linewidth=3.0, xerr = 0.0, yerr = 1000*z,
ax2.set_ylabel('exponential y-values', color='r', **axis_font)
for tl in ax2.get_yticklabels():
ax2.legend(loc=1, prop=font_prop)
for label in ax2.get_yticklabels():
#ax2.ticklabel_format(axis='y', style='sci', scilimits=(-2,2))

plb.savefig('test.png', bbox_inches='tight')

Which generates the plot shown below.

test.png <>

Now the question is about the line (two ways of doing the same):
#ax2.ticklabel_format(axis='y', style='sci', scilimits=(-2,2))

As can be seen from the plot, the 1e4 has both a different size and color
than the rest of the y-axis. I have tried so many methods, but it just
remains the same no matter. Can anyone help?


View this message in context:
Sent from the matplotlib - users mailing list archive at

I think that "1e4" is a offset text, and not a part of ax2's yticklabels, so
any color or font settings for yticklabels will not affect it.

It's seems the offset text only uses matplotlib's default rcParams to draw,
so my solution is to change rcParams.

Try add these 4 lines before your plot code:

import matplotlib as mpl

What you set here will become default settings of matplotlib.
For more details of rcParams, check this:
I hope this will solve your problems.


View this message in context:
Sent from the matplotlib - users mailing list archive at

And it works perfectly, thank you very much!


View this message in context:
Sent from the matplotlib - users mailing list archive at