Search code examples
pythonplotpyx

PyX Python: How to change the font size in the color bar?


Suppose you have the Python PyX code (from here):

 g = graph.graphxy(height=8, width=8,
              x=graph.axis.linear(min=re_min, max=re_max, title=r"$\Re(c)$"),
              y=graph.axis.linear(min=im_min, max=im_max, title=r'$\Im(c)$'))
g.plot(graph.data.points(d, x=1, y=2, color=3, title="iterations"),
   [graph.style.density(gradient=color.rgbgradient.Rainbow)])
g.writeEPSfile()

with the resulting plot

enter image description here

Question: How to change the font size in the color bar to make the 0, 2, 4, 6, 8, 10 larger?


Solution

  • The easiest way to change all font sizes is to change the xscale, like unit.set(xscale=2).

    To specifically change the size of the labels of the key graph, you need to pass your own keygraph and provide proper settings to the axis painter. Here is the code:

    kg = graph.graphx(xpos=9, length=8, x_title="iterations", x_painter_labelattrs=[text.size.Large])
    g.plot(graph.data.points(d, x=1, y=2, color=3),
           [graph.style.density(gradient=color.rgbgradient.Rainbow, keygraph=kg)])
    g.insert(kg)