我使用此代码生成图。
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
x = np.array([0,1,2,3])
y = np.array([0,0.7, 1.4, 2.1])
my_xticks = ['a', 'b', 'c', 'd']
plt.xticks(x, my_xticks)
plt.yticks(np.arange(y.min(), y.max(), 0.7))
plt.plot(x, y)
for i in range(0,5):
plt.hlines(i*(2.1/5),0,4,color='b')
plt.show()
获得以下情节。