x值与y的Matplotlib线图

2024-05-20 19:54:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个值x的列表,我想在y轴上绘制(带线)。

也就是说,如果x=[3、5、2、4]和y=['A'、'B'、'C'、'D'],则绘图可能如下所示(除非不是手绘的):

the plot style I mean

我恐怕在matplotlib.pyplot docs/SO/google中看不到任何指向正确方向的东西,甚至没有什么可以称之为正确方向的东西。有什么线索吗?


Tags: 绘图docs列表somatplotlibgoogle绘制指向
1条回答
网友
1楼 · 发布于 2024-05-20 19:54:02

我想你在找这样的东西

import numpy as np
import matplotlib.pyplot as plt

fig,ax = plt.subplots(1)

# create some x data and some integers for the y axis
x = np.array([3,5,2,4])
y = np.arange(4)

# plot the data
ax.plot(x,y)

# tell matplotlib which yticks to plot 
ax.set_yticks([0,1,2,3])

# labelling the yticks according to your list
ax.set_yticklabels(['A','B','C','D'])

相关问题 更多 >