2

When I do a contour plot, things go as expected

x = (np.linspace(0, 10))
y = (np.linspace(0, 10))
X, Y = np.meshgrid(x, y)
plt.contour(X, Y, np.sqrt(X) * Y)

enter image description here

However, when I set the axis to log-log, nothing shows. When I enter the following code, pyplot only shows a blank screen. Is this expected behavior? How can I make the contour plot on a log-log axis?

import matplotlib.pyplot as plt
import numpy as np
x = (np.linspace(0, 10))
y = (np.linspace(0, 10))
X, Y = np.meshgrid(x, y)
plt.contour(X, Y, np.sqrt(X) * Y)
plt.xscale('log')
plt.yscale('log')
plt.show()

1 Answer 1

3

The reason you don't see anything is because the axis limits are too narrow. Because 0 is in your dataset, log(0) isn't defined, so the limits on your axis aren't clear and defaults to a narrow range around 10. If you expand your x and y axis you should see some your data.

plt.xlim(1, 10)
plt.ylim(1, 10)
Sign up to request clarification or add additional context in comments.

1 Comment

I think it's advisable to then use np.logspace instead of np.linspace too

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.