pythonbar-chartaxis-labelspyx

Python Pyx: bar chart axis options


I am plotting a bar chart in PyX but the commands are different to continous plots.

I have something like this:

enter image description here

Q1) How to print only some (eg. just the even numbers 2, 4, 6, ...) on the x-axis?

Q2) How to give a axis label name to the y-axis?

Here is a minimal code (from here)


g = graph.graphxy(width=8, x=graph.axis.nestedbar())
g.plot([graph.data.file("minimal.dat", xname="$0, 0", y=2),
        graph.data.file("minimal.dat", xname="$0, 1", y=3)],
       [graph.style.bar()])
g.writeEPSfile("compare")

Solution

  • from pyx import *
    
    subaxes = {i+1: graph.axis.bar(dist=0, title=str(i+1) if i%2 else None,
                               painter=graph.axis.painter.bar(nameattrs=None), linkpainter=None)
               for i in range(12)}
    g = graph.graphxy(width=8, x=graph.axis.nestedbar(subaxes=subaxes, painter=graph.axis.painter.bar(nameattrs=None)), y_title="y axis title")
    g.plot([graph.data.file("minimal.dat", xname="$0, 0", y=2),
            graph.data.file("minimal.dat", xname="$0, 1", y=3)],
           [graph.style.bar()])
    g.writeEPSfile("compare")
    

    Q1) Bar axes always use the subaxes names for the names shown by the painter. Currently there is no way around this. However, you could use titles of the subaxes instead, and provide proper titles yourself like shown in the solution.

    Please also note, that bar axes do not use numeric values and do not use a parter to generate ticks and labels.

    Q2) If I properly understand your question, just set an axis title for the y axis.