pyx-project / pyx

Repository of PyX, a Python package for the creation of PostScript, PDF, and SVG files.
https://pyx-project.org/
GNU General Public License v2.0
109 stars 18 forks source link

Change tick style on all borders #17

Closed sphh closed 4 years ago

sphh commented 4 years ago

How do I change the tick style on all borders?

I use

axispainter = pyx.graph.axis.painter.regular(
    tickattrs=[
        pyx.attr.changelist(
            [pyx.style.linewidth.THIn,     # Main ticks on x and y axis
             pyx.style.linewidth.THIn      # Minor thicks on x and y axis
            ])])

but this does only change the ticks on the primary x and y axis (bottom and left). Even if I add more pyx.style.linewidth.THIn to oyx.attr.changelist([...]), it does not change the ticks on the right and top axis …

wobsta commented 4 years ago

Well, the top axis, the axis x2, is created by the graph, if not given. It is a linked axis to x. It uses a different painter, which has labelattrs and textattrs being none.

Now, as the anchored axis x is created by the graph, you cannot simply pass a linked axis of the same graph directly. But ... PyX itself has the same issue, it needs to set a painter for the linked axis, which needs to be different from the original painter, as it needs to suppress the labels and the title. It is done by the linkpainter attribute of the axis. You just have to adjust that, too.

from pyx import *

mytickattrs=[attr.changelist([style.linewidth.Thin,
                              style.linewidth.THIn])]

myaxispainter = graph.axis.painter.regular(tickattrs=mytickattrs)
mylinkpainter = graph.axis.painter.linked(tickattrs=mytickattrs)
xaxis = graph.axis.linear(min=-15, max=15,
                          painter=myaxispainter,
                          linkpainter=mylinkpainter)

g = graph.graphxy(width=8, x=xaxis)
g.plot(graph.data.function("y(x)=sin(x)/x"))
g.writePDFfile()

It would probably be nice to be able to alter a painter (by call) into a new instance, to make the update step from a painter to a linkedpainter ... we will see in the future, how we progress here.

sphh commented 4 years ago

So many thanks. I got it working now! I would never have figured this out on my own …