0

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()

enter image description here

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.

enter image description here

Using the origninal plot, how can I set the x-axis to see the actual data?

0

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.