Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve linestyles (including a fix for broken line styles in CairoMakie) #807

Closed
greimel opened this issue Jan 7, 2021 · 5 comments · Fixed by JuliaPlots/AbstractPlotting.jl#593 or JuliaPlots/GLMakie.jl#157

Comments

@greimel
Copy link
Contributor

greimel commented Jan 7, 2021

Bug: Lines in CairoMakie

image

This shows dot, dashdot and dash.

This is because the length of the dashes

https://github.com/JuliaPlots/AbstractPlotting.jl/blob/d78a16de02b73d3548942d43e6664cf0dfa54a5d/src/conversions.jl#L684

is in multiples of line width in CairoMakie.

https://github.com/JuliaPlots/CairoMakie.jl/blob/b0121ad11ab77eb79544942788c341972d31a53c/src/primitives.jl#L49

Compare GLMakie

image

This shows dot, dashdot and dash.

Proposal 1

So, what we could do is, to multiply with 3 * linewidth in CairoMakie.

Proposal 2

But while we're at it, we could also imporve line styles. dashdot doesn't really match what know from other packages. (the gap to both sides of the dot should be equal).

We could probably model linestyles after tikz.

where the patterns are given by

\tikzstyle{solid}=                   [dash pattern=]
\tikzstyle{dotted}=                  [dash pattern=on \pgflinewidth off 2pt]
\tikzstyle{densely dotted}=          [dash pattern=on \pgflinewidth off 1pt]
\tikzstyle{loosely dotted}=          [dash pattern=on \pgflinewidth off 4pt]
\tikzstyle{dashed}=                  [dash pattern=on 3pt off 3pt]
\tikzstyle{densely dashed}=          [dash pattern=on 3pt off 2pt]
\tikzstyle{loosely dashed}=          [dash pattern=on 3pt off 6pt]
\tikzstyle{dashdotted}=              [dash pattern=on 3pt off 2pt on \the\pgflinewidth off 2pt]
\tikzstyle{densely dashdotted}=      [dash pattern=on 3pt off 1pt on \the\pgflinewidth off 1pt]
\tikzstyle{loosely dashdotted}=      [dash pattern=on 3pt off 4pt on \the\pgflinewidth off 4pt]

Source: https://tex.stackexchange.com/questions/45275/tikz-get-values-for-predefined-dash-patterns

Your Feedback needed

Now that I've figured all this out, it would be quite simple to prepare a PR if this is wanted.

The question is, if we want everything as multiples of linewidth, or not. Right now, there is an inconsistency across backends. (I would use the patterns above with 1pt == \pgflinewidth == linewidth)

@jkrumbiegel
Copy link
Member

really cool summary, thanks! I think we should try to mirror existing packages' handling of dashes. I just remember that I fixed the GLMakie vs CairoMakie discrepancy of relative / absolute with the diff(pattern) part in CairoMakie, and that to me it seemed logical to have linewidth-dependent patterns because otherwise the preset for dashed if given in points can only be valid for one corresponding linewidth.

@greimel
Copy link
Contributor Author

greimel commented Jan 7, 2021

GR.jl

Among all the plotting packages in Julia I found GR.jl to be the most visually appealing (now beaten by AbstractPlotting 0.15). I tried to find the definition of dash-patterns in their C-source, but I gave up.

Plots.jl

Plots.jl seems to be inconsistent across backends. Below screenshots from their docs.

GR, PyPlot and Plotly-backend seem scaled:
image
(here Plotly)

while PGFPlotsX isn't.
image

(This makes sense, if they use the default tikz linestyles--that I posted above--which are not scaled).

@greimel
Copy link
Contributor Author

greimel commented Jan 7, 2021

Are there any objections to using the tikz pattern definitions that I posted above, with 1pt == linewidth?

@jkrumbiegel
Copy link
Member

jkrumbiegel commented Jan 7, 2021

To me the pyplot behavior seems much more desirable, because what the user means by "dashed" is not a specific gap width in pt but the look of dashes, no matter the line width. So the compromise could be to make the preset values linewidth-relative, but not the manually given ones such as [1, 3, 1, 3]. Or we make everything linewidth-relative, which I like more I think.

No matter which format, we should definitely adjust the patterns so they look like the examples you showed from other packages.

@greimel
Copy link
Contributor Author

greimel commented Jan 7, 2021

Please have a look at the two open PRs. I can make a follow-up PR for WGLMakie once the other two PRs are approved by you.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants