3

I am attempting to plot differential cross-sections of nuclear decays and so the magnitudes of the y-axis are around 10^-38 (m^2) pylab as default plots the axis as 0.0,0.2,0.4... etc and has a '1e-38' at the top of the y-axis.

I need to increase the font size of just this little bit, I have tried adjusting the label size

py.tick_params(axis='y', labelsize=20)

but this only adjusts the labels 0.0,0.2,0.4....

Many thanks for all help

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
user3412782
  • 561
  • 1
  • 4
  • 9

1 Answers1

3

You can access the text object using the ax.yaxis.get_offset_text().

import numpy as np
import matplotlib.pyplot as plt

# Generate some data
N = 10
x = np.arange(N)
y = np.array([i*(10**-38) for i in x])

fig, ax = plt.subplots()

# Plot the data
ax.plot(x,y)

# Get the text object
text = ax.yaxis.get_offset_text()

# Set the size.
text.set_size(30) # Overkill!

plt.show()

I've written the solution above using matplotlib.pyplot rather than pylab though if you absolutely have to use pylab then it can be changed (though I'd recommend you use matplotlib.pyplot in any case as they are pretty much identical you can just do a lot more with pyplot easier).

Edit

If you were to use pylab then the code would be:

pylab.plot(x, y)

ax = pylab.gca() # Gets the current axis object

text = ax.yaxis.get_offset_text() # Get the text object

text.set_size(30) # # Set the size.

pylab.show()

An example plot with an (overkill!) offset text.

Plot

Community
  • 1
  • 1
Ffisegydd
  • 51,807
  • 15
  • 147
  • 125
  • Fantastic thank you, I've never used pyplot before but all other commands, that I used with pylab, seem to have worked perfectly! Thank you for such a quick and thorough answer! – user3412782 Apr 30 '14 at 16:14
  • 1
    If you do want to use `pylab` then you can use the command `pylab.gca().yaxis.get_offset_text().set_size(30)` which will do the same job as everything I've typed above (but it looks a bit messier :)) – Ffisegydd Apr 30 '14 at 16:15