I wanna make a bar graph plot in PyX (see here) using the code
from pyx import *
g = graph.graphxy(width=8, x=graph.axis.bar())
g.plot(graph.data.file("minimal.dat", xname=0, y=2), [graph.style.bar()])
g.writePDFfile("minimal")
and the data
1 0.4
2 0.5
3 0.2
4 0.1
5 0.0
I get the plot
Question: how to force the y-axis maximum to be 1.0 instead of 0.5?
Searching pyx bar y limit
in Google I found [PyX-user] How do I set ymin for a bargraph?
It suggests to create own y axis with max=
axis_y = graph.axis.linear(max=1) # ,title="y axis")
g = graph.graphxy(width=8, x=graph.axis.bar(), y=axis_y)
and this gives me expected result.
Later I found other example which uses x_max=...
directly in graphxy
so I tried y_max
and it works.
g = graph.graphxy(width=8, x=graph.axis.bar(), y_max=1)
Full working code used for tests.
I use io.String
only to create file-like object
in memory - so everyone can simply copy and test it.
from pyx import *
import io
file_obj = io.StringIO("""
1 0.4
2 0.5
3 0.2
4 0.1
5 0.0
""")
#axis_y = graph.axis.linear(max=1, title="y axis")
#g = graph.graphxy(width=8, x=graph.axis.bar(), y=axis_y)
g = graph.graphxy(width=8, x=graph.axis.bar(), y_max=1)
# g.plot(graph.data.file("minimal.dat", xname=0, y=2), [graph.style.bar()])
g.plot(graph.data.file(file_obj, xname=0, y=2), [graph.style.bar()])
g.writePDFfile("minimal")