Anurag Mishra
Anurag Mishra

Reputation: 11

Using a logarithmic scale in matplotlib

I have the following plot in which the X range is very wide and the shape of the graph near 1 MeV to 0.1 MeV is suppressed.

I want a plot where the X scale has equal separation (or equal grid) between 10,1,0.1 MeV. enter image description here

Upvotes: 0

Views: 7916

Answers (2)

cattt84
cattt84

Reputation: 951

also consider ax.set_xscale("log") http://matplotlib.org/examples/pylab_examples/aspect_loglog.html

Upvotes: 2

tmdavison
tmdavison

Reputation: 69223

You can use matplotlib's semilogx function instead of plot to make the x axis logarithmic.

Here's a short example:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0.01,14,0.01)
y = np.log(100*x)

fig,(ax1,ax2) = plt.subplots(2)

ax1.plot(x,y)
ax1.set_xlim(x[-1],x[0])
ax1.set_title('plot')

ax2.semilogx(x,y)
ax2.set_xlim(x[-1],x[0])
ax2.set_title('semilogx')

plt.show()

enter image description here

Upvotes: 4

Related Questions