在 Python 中向 PyQT 图表添加单独的轴标签?

发布于 2025-01-12 02:09:00 字数 324 浏览 3 评论 0原文

我正处于项目的最后部分,我们只需要制作一个图表,显示节目和电影的数量及其收视趋势。我有 4 个不同的条形图项目,我想知道是否有办法为每个单独的条形图添加标签?例如,这是其中一个栏

y4 = [fourth]
x4 = [4.33]
bg4 = pg.BarGraphItem(x=x4, height=y4, width=0.2, brush='red', setLabel="Shows Down")
bg4.setX(0)
bg4.setY(0)

在此处输入图像描述

I'm in the final portion of my project and we just need to make a graph showing the number of shows and movies with their rating trend. I have 4 different bar graph items and I was wondering if there's a way to add labels to each individual bar? For example here's one of the bars

y4 = [fourth]
x4 = [4.33]
bg4 = pg.BarGraphItem(x=x4, height=y4, width=0.2, brush='red', setLabel="Shows Down")
bg4.setX(0)
bg4.setY(0)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福还没到 2025-01-19 02:09:01

您可以使用一组 TextItem 并将栏设置为其父级:

text = pg.TextItem('Some bar', angle=90, color='#ffff00')
# reparent the item and make it a child of the bar
text.setParentItem(bg4)
# set the position to the x of the bar
text.setX(x4[0])
# use the x as left of the text and the y as vertical middle (referenced
# to the text orientation)
text.setAnchor(QPointF(0, .5))

请注意,您不需要创建单独的条形,只要它们属于同一组并共享相同的颜色即可:只需添加 xheight 作为列表他们的立场和价值观。

You could use a group of TextItem and set the bar as their parent:

text = pg.TextItem('Some bar', angle=90, color='#ffff00')
# reparent the item and make it a child of the bar
text.setParentItem(bg4)
# set the position to the x of the bar
text.setX(x4[0])
# use the x as left of the text and the y as vertical middle (referenced
# to the text orientation)
text.setAnchor(QPointF(0, .5))

Note that you don't need to create individual bars as long as they are part of the same group and share the same colors: just add the x and height as lists of their positions and values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文