简体   繁体   中英

Plot horizontal line on a logit x-axis

I am trying to plot a horizontal line in a plot that has a logit x-aixs. The problem is, that the line simply doesnt show up. If I change the x-axis to "linear" or "log" the horizontal line shows as intended.

Am I doing something wrong, or is this just not intended. I would really like to keep the logit scale as it currently is.

Here is the example code to illustrate the problem:

import matplotlib.pyplot as plt
import pandas as pd

x = [0.025, 0.017, 0.167, 0.375,
     0.241, 0.16, 0.192, 0.833,
     0.063, 0.016, 0.056, 0.052,
     0.047, 0.025, 0.057, 0.063,
     0.2, 0.273, 0.273, 0.051]

y = [158., 239., 18., 8., 29., 25., 26., 6., 48., 314., 54.,
     58., 316., 119., 87., 239., 25., 11., 11., 59.]

plt.scatter(x, y)
plt.hlines(20, 0, 1) # -> THIS LINE DOESNT SHOW UP IN THE PLOT
plt.yscale("log")
plt.xscale("logit")
plt.show()

import matplotlib.pyplot as plt
import pandas as pd

x = [0.025, 0.017, 0.167, 0.375,
     0.241, 0.16, 0.192, 0.833,
     0.063, 0.016, 0.056, 0.052,
     0.047, 0.025, 0.057, 0.063,
     0.2, 0.273, 0.273, 0.051]

y = [158., 239., 18., 8., 29., 25., 26., 6., 48., 314., 54.,
     58., 316., 119., 87., 239., 25., 11., 11., 59.]

plt.scatter(x, y)
plt.hlines(20, 0, 1) # -> CHANGING XSCALE TO LINEAR AND THE LINE APPEARS
plt.yscale("log")
plt.xscale("linear") # -> CHANGING XSCALE TO LINEAR AND THE LINE APPEARS
plt.show()

You could manually create the line with plt.plot()

import matplotlib.pyplot as plt
import pandas as pd

x = [0.025, 0.017, 0.167, 0.375,
     0.241, 0.16, 0.192, 0.833,
     0.063, 0.016, 0.056, 0.052,
     0.047, 0.025, 0.057, 0.063,
     0.2, 0.273, 0.273, 0.051]

y = [158., 239., 18., 8., 29., 25., 26., 6., 48., 314., 54.,
     58., 316., 119., 87., 239., 25., 11., 11., 59.]

plt.scatter(x, y)
#plt.hlines(20, 0, 1) # -> THIS LINE DOESNT SHOW UP IN THE PLOT
plt.plot([min(x),max(x)],20)
plt.yscale("log")
plt.xscale("logit")
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM