在坐标轴上添加特定刻度的坐标
当我们需要标记一列数的阈值时往往希望在阈值的地方做一条平行于横轴的虚线,即实现下图:
import matplotlib.pyplot as plt
import numpy as np
x=[np.random.randint(100) for i in range(50)]
# print(x)
y=[np.random.randint(100) for i in range(50)]
# print(y)
plt.scatter(x, y, c='blue', s=5, label='point')
plt.axhline(y=15.5,color="red",label='threhold',linestyle=':')
tmp=[i for i in range(0,110,10)]
tmp.append(15.5)
plt.yticks(tmp)
plt.legend(loc='lower right')
plt.plot()
plt.show()