gpt4 book ai didi

python - 如何在pyqtgraph中的一个轴上绘制两个barh?

转载 作者:太空宇宙 更新时间:2023-11-03 16:43:32 26 4
gpt4 key购买 nike

我需要这样的东西: enter image description here演示数据:

bottom10
Out[12]:
0 -9.823127e+08
1 -8.069270e+08
2 -6.030317e+08
3 -5.709379e+08
4 -5.224355e+08
5 -4.755464e+08
6 -4.095561e+08
7 -3.989287e+08
8 -3.885740e+08
9 -3.691114e+08
Name: amount, dtype: float64

top10
Out[13]:
0 9.360520e+08
1 9.078776e+08
2 6.603838e+08
3 4.967611e+08
4 4.409362e+08
5 3.914972e+08
6 3.547471e+08
7 3.538894e+08
8 3.368558e+08
9 3.189895e+08
Name: amount, dtype: float64

matplotlib 的相同问题在这里:how to plot two barh in one axis但是pyqtgraph中没有ax.twiny()。还有别的办法吗?

最佳答案

我发现了一个小部件“BarGraphItem”,它没有在官方文档中编写( PyQtGraph’s Widgets List )。它可以“旋转()”来使barh像matplotlib一样。它并不完美,但有效! enter image description here

import pyqtgraph as pg
import pandas as pd
import numpy as np

bottom10 = pd.DataFrame({'amount':-np.sort(np.random.rand(10))})
top10 = pd.DataFrame({'amount':np.sort(np.random.rand(10))[::-1]})
maxtick=max(top10.amount.max(),-bottom10.amount.min())*1.3

win1 = pg.plot()
axtop=pg.BarGraphItem(x=range(len(top10)),height=top10.amount,width=0.6,brush='r')
axtop.rotate(-90)
win1.addItem(axtop)
axbt=pg.BarGraphItem(x=range(len(top10)),height=-bottom10.amount,y0=maxtick+bottom10.amount,width=0.6,brush='g')
axbt.rotate(-90)
win1.addItem(axbt)

关于python - 如何在pyqtgraph中的一个轴上绘制两个barh?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36551044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com