Search code examples
pythonmatplotlibplotpyx

Python Pyx Plot: How to split graph key?


Consider below PyX plot

enter image description here

How to arrange graph key so that instead of one verticle list of 4 entries, there are 2 lists (each of 2 entries) side by side?

I mean, instead of key:

x = y^4,

x = y^2,

x = y,

y = x^4,

Having key:

x = y^4, x = y

x = y^2, y = x^4

Here is the code:

from pyx import *
g = graph.graphxy(width=8,
              x=graph.axis.linear(min=0, max=2),
              y=graph.axis.linear(min=0, max=2),
              key=graph.key.key(pos="br", dist=0.1))
g.plot([graph.data.function("x(y)=y**4", title=r"$x = y^4$"),
    graph.data.function("x(y)=y**2", title=r"$x = y^2$"),
    graph.data.function("x(y)=y", title=r"$x = y$"),
    graph.data.function("y(x)=x**4", title=r"$y = x^4$")],
   [graph.style.line([color.gradient.Rainbow])])
g.writePDFfile("change")

Solution

  • There is an argument colums for graph.key, which happens to be one, and can be set to two or whatever else you want. http://pyx.sourceforge.net/manual/graph.html#module-graph.key