KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

H and VLine with logarithmic axes. #193

Closed korsbo closed 4 years ago

korsbo commented 4 years ago

The start and end points of HLine and VLine are incorrect when the respective axis is in mode = "log"

@pgf Axis({ymode="log", xmode="log"},
    PlotInc(
        Expression("x^2"),
    ),
    VLine(1.),
    HLine(5.),
    )

demo

The print_tex output shows

\begin{axis}[ymode={log}, xmode={log}]
    \addplot+
        {x^2};
    \draw (1.0,\pgfkeysvalueof{/pgfplots/ymin})--(1.0,\pgfkeysvalueof{/pgfplots/ymax});
    \draw (\pgfkeysvalueof{/pgfplots/xmin},5.0)--(\pgfkeysvalueof{/pgfplots/xmax},5.0);
\end{axis}

and some tinkering revealed that I get the desired result if I exponentiate the appropriate ymin and xmin:

@pgf ax = Axis({ymode="log", xmode="log"},
    PlotInc(
        Expression("x^2"),
    ),
    raw"
    \draw (1.0,10^\pgfkeysvalueof{/pgfplots/ymin})--(1.0,10^\pgfkeysvalueof{/pgfplots/ymax});
    \draw (10^\pgfkeysvalueof{/pgfplots/xmin},5.0)--(10^\pgfkeysvalueof{/pgfplots/xmax},5.0);
    "
    )

demo2

tpapp commented 4 years ago

Thanks for calling attention to this. HLine and VLine are hacks, and I am not sure how to work around this in a robust way, but I will do some digging the docs.

korsbo commented 4 years ago

I thought about just submitting a PR rather than an issue, but I don't know how to access information about whether the axis is logarithmic from where the XLine latex code is generated.

tpapp commented 4 years ago

I could think of a lazy expansion scheme for plot elements, but before we complicate the code too much I will search for a solution using pgfplots/LaTeX/TikZ.

korsbo commented 4 years ago

I found a neat solution, I'll PR shortly.