4

everything is in the title, how to change the fontsize of the ticks using pyqtgraph ?

Thx

Gregos38
  • 53
  • 1
  • 3
  • everything is probably in the doc. Maybe as your code ? and your trials ? – iFlo Jan 18 '17 at 15:52
  • Everything is in google! In how far does this not help? Please make sure you have [taken the tour](http://stackoverflow.com/tour), and especially have read [How to ask a question](http://stackoverflow.com/help/how-to-ask). – ImportanceOfBeingErnest Jan 19 '17 at 09:55
  • Sorry for being not precise enough. The documentation of pyqtgraph didn't help me and google neither. I saw a post on the pyqtgraph support forum that indicates to use the setStyle function with the keyword 'tickFont' but I can not figure out how to use it properly. So if create my graph with self.my_plot = pg.PlotWidget() and then use self.my_plot.setStyle(xxx), what I should put instead of xxx to have for example a fontsize twice bigger compared to the original one ? – Gregos38 Jan 20 '17 at 16:37

3 Answers3

7

I think the only way to change the font size of the ticklabels in pyqtgraph is to first create a new font within PyQt and set the fontsize to it. Then this font can be applied to the ticks.

font=QtGui.QFont()
font.setPixelSize(20)
plot.getAxis("bottom").tickFont = font

Initially I would have thought that something like
plot.getAxis("bottom").setStyle(tickFont = font)
should work as well, but for some reason it doesn't.

Once the font size has increased, it may make sense to adapt the tickOffset as well. Find a complete running code is below.

import numpy as np
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg


app = QtGui.QApplication([])

x = np.linspace(-50, 50, 1000)
y = np.sin(x) / x

win = pg.GraphicsWindow()
plot = win.addPlot(x=x, y=y, title="Plot")
plot.setLabel('bottom', "some x axis label")

font=QtGui.QFont()
font.setPixelSize(20)
plot.getAxis("bottom").tickFont = font
plot.getAxis("bottom").setStyle(tickTextOffset = 20)


if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
6

For Pyqtgraph 0.11 the syntax has changed to:

font=QtGui.QFont()
font.setPixelSize(20)
plot.getAxis("bottom").setStyle(tickFont = font)

or

plot.getAxis("bottom").setTickFont(font)
Josh Whale
  • 61
  • 1
  • 3
2

There's not much documentation on this it seems like, but anybody else that was struggling with this like I did might find the source code for AxisItem useful.

Elliot Young
  • 291
  • 5
  • 5