【问题标题】:How to change the font of Axis label in PyqtgraphPyqtgraph中如何改变Axis标签的字体
【发布时间】:2022-12-03 02:49:46
【问题描述】:

我有一个自定义字体,我可以在图表的标题中设置这个字体,我需要帮助设置轴标签字体。(左,底部轴标签)

我可以像这样将字体设置为图表的标题

    graphWidget = pyqtgraph.PlotWidget()
    graph = graphWidget.getPlotItem()
    graph.titleLabel.item.setFont(font)

我想知道是否有任何类似的方法来设置轴标签的字体。

【问题讨论】:

    标签: python pyqt pyqt5 pyside2 pyqtgraph


    【解决方案1】:

    要将自定义 QFont 设置为轴标签,您必须为每个 axislabel setFont

    这是一个简短的示例,它将标题、底部和左轴的字体系列更改为 Times

    import sys
    
    import pyqtgraph
    from PyQt5.QtGui import QFont
    from PyQt5.QtWidgets import QApplication
    
    app = QApplication(sys.argv)
    
    # Define your font
    my_font = QFont("Times", 10, QFont.Bold)
    
    graphWidget = pyqtgraph.PlotWidget()
    graphWidget.setTitle("My plot")
    
    # Set label for both axes
    graphWidget.setLabel('bottom', "My x axis label")
    graphWidget.setLabel('left', "My y axis label")
    
    # Set your custom font for both axes
    graphWidget.getAxis("bottom").label.setFont(my_font)
    graphWidget.getAxis("left").label.setFont(my_font)
    
    graph = graphWidget.getPlotItem()
    # Set font for plot title
    graph.titleLabel.item.setFont(my_font)
    
    graphWidget.show()
    app.exec()
    

    【讨论】:

      猜你喜欢
      • 2020-05-31
      • 2011-06-23
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多