Description
Bug summary
Fill-between cannot handle logit axis, if there is 0 or 1 in the data.
I wish to draw a ROC curve with estimation uncertanity in logit-scale (like is customary in DET curves). This means I need a lineplot, a fill_between, data from 0 to 1, and logit axes.
For the datapoints being exactly 0 or 1, the transformation fails (as expected). But plt.plot
fails gracefully by removing the offending data. plt.fill_betweenx
removes the bad data, but the fill logic fails badly.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,1,100)
y = 1-(2/(1+x)-1)**10
fig,ax = plt.subplots(1,3)
x1=x+x*(1-x)
x2=x-x*(1-x)
# regular plot
ax[0].plot(x,y)
ax[0].fill_betweenx(x1=x1,x2=x2,y=y,alpha=0.3)
# plot with transformed axes
ax[1].plot(x,y)
ax[1].fill_betweenx(x1=x1,x2=x2,y=y,alpha=0.3)
ax[1].set_xscale('logit')
ax[1].set_yscale('logit')
# remove offending points
idx = (x1>0) & (x1<1) & (x2>0) & (x2<1) & (y>0) & (y<1)
ax[2].plot(x,y)
ax[2].fill_betweenx(x1=x1[idx],x2=x2[idx],y=y[idx],alpha=0.3)
ax[2].set_xscale('logit')
ax[2].set_yscale('logit')
Actual outcome
The image to the left shows the filling correctly, but without transformed axes.
In the mid, , the filling is "outside" the region, which is the bug.
To the right, I have manually removed the offending data points, and it works as it should
Expected outcome
The plot in the middle should look like the one to the right.
Additional information
The tranformation produces points that fall in +-inf. Or maybe NaN? The seems to throw the fill-between logic off.
Operating system
Windows
Matplotlib Version
3.5.1
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.7.1
Jupyter version
6.4.8
Installation
conda