matplotlib 如何在hlines上添加标记和编号

zfciruhq  于 2023-05-01  发布在  其他
关注(0)|答案(1)|浏览(101)

我想创建一个有4个图的 Jmeter 板,有2条hlines。

f, axs = plt.subplots(2,2,figsize=(16,14))
x=lplt['pts']
y=lplt['time']

axs[0,1].hlines(y, xmin = 0 , xmax = lplt['pts'], color='g')
axs[1,1].hlines(y, xmin = 0 , xmax = lplt['pts'], color='skyblue', linestyles= 'solid')
axs[1,0].barh(y, x, linewidth = 2)
axs[0,0].plot(y, x, marker = "o", linewidth = 2)

plt.show()

我想在图的前面加上绿色的数字,例如:

最后一个情节是这样的:

7hiiyaii

7hiiyaii1#

f, axs = plt.subplots(2,2,figsize=(16,14))
x = [20, 10, 5, 15]
y = ["A", "B", "C", "D"]

ax0 = axs[0, 0]
ax0.plot(y, x, marker = "o", linewidth = 2)

ax1 = axs[0, 1]
ax1.hlines(y, xmin=0 , xmax=x, color='green')
for xv, yv in zip(x, y):
    ax1.text(x=xv, y=yv, s=xv)

ax2 = axs[1, 0]
ax2.barh(y, x, linewidth=2)

ax3 = axs[1,1]
ax3.hlines(y, xmin=0 , xmax=x, color='skyblue', linestyles= 'solid')
ax3.scatter(x, y)

plt.show()

相关问题