Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug report
Bug summary
Plotting negative values on a log scale is possible. However it changes the axis limits in a seemingly arbitrary way.
Code for reproduction
The following shows three scatter plots. Thex
values
(1) are all positive
(2) contain one negative value
(3) have the negative value filtered out
import numpy as np; np.random.seed(1)import matplotlib.pyplot as pltx = np.random.rayleigh(100,400)y = np.random.rand(len(x))fig, (ax,ax2, ax3) = plt.subplots(nrows=3)ax.scatter(x,y)ax.set_xscale("log")ax.set_title("Scatter of all-positive values")ax2.scatter(x-2,y)ax2.set_xscale("log")ax2.set_title("Scatter with one negative value")cond = x-2 > 0ax3.scatter((x-2)[cond],y[cond])ax3.set_xscale("log")ax3.set_title("Expected scatter with one negative value")plt.tight_layout()plt.show()
Actual outcome
The second subplot, where the data contains a negative value, shows only part of the valid data, because the axis is autoscaled to some seemingly arbitrary region.
Expected outcome
The third subplot would be the expected outcome with the axis autoscaled to show all points.
One could also argue that plotting negative data on a log scale should not be supported at all, and that it should be the user's responsibility to make sure the data is positive. In that case however it would make sense to issue a warning instead of just plotting something arbitrary.
Matplotlib version
- Operating system: Windows 8.1
- Matplotlib version: 2.2
- Matplotlib backend: any
- Python version: 2.7.10