Reputation: 17631
I am having difficulty understanding how matplotlib.pyplot.xlim()
works.
I am plotting a simple plot of x values vs y values. The y values are numerical points in the range of 100-600. The x values are of magnitude e-09
to e-13
. So, I plot x against y. This is my plot, with generic pseudocode
import matplotlib.pyplot as plt
x = np.array
y = np.array
plt.plot(x,y)
plt.ylim(0,400)
plt.show()
As you can tell, there's plenty of structure between 0 and 0.5. I would like to look at that.
So, I try
plt.plot(x,y)
plt.xlim(0,0.5)
plt.ylim(0,400)
plt.show()
The output plot is completely blank. I see nothing.
So, I try, xlim= -1 to +1
plt.plot(x,y)
plt.xlim(-1,1)
plt.ylim(0,400)
plt.show()
This is the output plot.
Using the origninal plot, how can I set the x-axis to see the actual data?
Upvotes: 0
Views: 638
Reputation: 3363
If your x-values are of magnitude of 1e-9
till 1e-13
you have completely different length scales. In this case a logarithmic axis may be appropriate. Note that this works only if all x-values are strictly positive.
plt.xscale('log')
Upvotes: 1
Reputation: 9363
As you clearly mentioned
The x values are of magnitude e-09 to e-13.
So if you want to see the values that lie within 1e-8
and 0.5e-9
you should do:
plt.xlim(1e-8,0.5e-9)
instead of
plt.xlim(0,0.5)
where you have no values to show as the values of x are within e-09 to e-13.
Upvotes: 2