Show string values on x-axis in pyqtgraph

前端 未结 2 1300
一向
一向 2020-12-09 22:36

I want to display string values for ticks on x-axis in pyqtgraph. Right now I am unable to figure out how to do that.

Ex:

x = [\'a\', \'         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 23:16

    I find it easiest to prepare a list of indices and a list of your strings and then zip them together:

    ticks = [list(zip(range(5), ('a', 'b', 'c', 'd', 'e')))]
    

    You can get an existing AxisItem of a PlotWidget like so:

    pw = pg.PlotWidget()
    xax = pw.getAxis('bottom')
    

    And finally set the ticks of the axis like so:

    xax.setTicks(ticks)
    

    As far as I can tell, PlotWidgets automatically include 'bottom' and 'left' AxisItems, but you can create and add others if you desire.

提交回复
热议问题