简体   繁体   English

Plot logit x 轴上的水平线

[英]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.我正在尝试 plot 在具有 logit x-aixs 的 plot 中的水平线。 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.如果我将 x 轴更改为“线性”或“对数”,水平线将按预期显示。

Am I doing something wrong, or is this just not intended.我是不是做错了什么,或者这不是故意的。 I would really like to keep the logit scale as it currently is.我真的很想保持目前的 logit 比例。

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()您可以使用 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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