kilojoules
kilojoules

Reputation: 10093

pyplot log-log contour plot doesn't work

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

Upvotes: 2

Views: 3503

Answers (1)

busybear
busybear

Reputation: 10590

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)

Upvotes: 3

Related Questions