pythonplotpyx

Python Pyx plot: changing spacing between dots in dotted line


I have plot in Pyx module with Python:

 g = graph.graphxy(width=8,
              x=graph.axis.linear(min=0, max=2),
              y=graph.axis.linear(min=0, max=2),
              )

 g.plot([graph.data.function("x(y)=y**4")],
   [graph.style.line([style.linestyle.dotted])])

 g.writeEPSfile("plot")

How to change the spacing between dots in dotted line?


Solution

  • Just use your own linestyle settings:

    c = canvas.canvas()
    c.stroke(path.line(0, 0, 10, 0), [style.linestyle(style.linecap.round, style.dash([0, 2]))])
    c.stroke(path.line(0, -1, 10, -1), [style.linestyle(style.linecap.round, style.dash([0, 4]))])
    c.stroke(path.line(0, -2, 10, -2), [style.linestyle(style.linecap.round, style.dash([0, math.pi])), style.linewidth(0.1)])
    c.writePDFfile(page_bboxenlarge=1)
    

    The first line is identical to style.linestyle.dotted, the second uses twice the distance between the dots, and the third shows a float as the distance and changes the linewidth as well. Note that the linewidth defines the size of the dots and also changes the distance between the dots, as the dash is values are scaled by the linewidth. A dotted line is build by a dashed line with zero length of the dashes and style.linecap.round as the line cap setting.

    Note that the linewidth is applied first (attribution order ... something not well documented).