python中的水平绘图

2024-05-14 09:38:39 发布

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

我在找一个顺时针旋转90度的图。类似的例子是“hist(x,orientation=”horizontal“)。有没有办法达到类似的方向。

#Make horizontal plots.
import random
import matplotlib.pyplot as plt
x = random.sample(range(1000), 100)
x
plt.plot(x) #orientation='horizontal'
plt.show()

Tags: importmakematplotlibaspltrandom方向hist
1条回答
网友
1楼 · 发布于 2024-05-14 09:38:39

plt.plot(x)根据y轴自动绘制x值。为了得到一个旋转的绘图,你必须绘制你的x值对x轴。所以你需要一个向量来表示y轴,它和你的样本有相同的长度。

import random
import matplotlib.pyplot as plt
import numpy as np

x=random.sample(1000)
y=np.arange(1000)
plt.plot(x,y)

使用plt.plot(x),matplotlib将x值作为y值,并自动生成x轴的向量。

相关问题 更多 >

    热门问题