Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BUG] labels are too close with LaTeXStrings #3884

Open
lmiq opened this issue Oct 18, 2021 · 9 comments
Open

[BUG] labels are too close with LaTeXStrings #3884

lmiq opened this issue Oct 18, 2021 · 9 comments

Comments

@lmiq
Copy link
Contributor

lmiq commented Oct 18, 2021

Details

The labels get overlapped here:

using Plots, LaTeXStrings
plot(rand(10),label=L"2\pi")
plot!(rand(10),label=L"2\pi")

image

It is not a GR issue (alone), as with GR alone it works:

julia> using GR

julia> plot(randn(10,2),labels=(L"2\pi", L"2\pi"))

image

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pyplot
plotlyjs
pgfplotsx x
unicodeplots
inspectdr
gaston

Versions

Plots.jl version:
Backend version (]st -m <backend(s)>):

(@v1.6) pkg> st -m Plots
      Status `~/.julia/environments/v1.6/Manifest.toml`
  [91a5bcdd] Plots v1.22.6

(@v1.6) pkg> st -m GR
      Status `~/.julia/environments/v1.6/Manifest.toml`
  [28b8d3ca] GR v0.61.0

Output of versioninfo():

julia> versioninfo()
Julia Version 1.6.3
Commit ae8452a9e0 (2021-09-23 17:34 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
@t-bltg
Copy link
Member

t-bltg commented Oct 18, 2021

Haven't I explained to use legend_hfactor in #3598 (comment) ?

There is no spacing (that's why legend_hfactor is for), but the labels do not overlap.

Here with dpi=300:

bar

@lmiq
Copy link
Contributor Author

lmiq commented Oct 18, 2021

This is related: #3598

Yet I wander if the default spacing should not be larger already (getting overlapping labels is not acceptable, while getting a larger spacing is about taste. With default spacing:

julia> plot(rand(10),label="2π")

julia> plot!(rand(10),label="2π")

image

And with legend_hfactor=1.5:

julia> plot!(rand(10),label="2π",legend_hfactor=1.5,extra_kwargs=:subplot)

image

@t-bltg
Copy link
Member

t-bltg commented Oct 18, 2021

getting overlapping labels is not acceptable

Yes, but in your mwe, I don't see any overlap.

@lmiq
Copy link
Contributor Author

lmiq commented Oct 18, 2021

Ok, in the MWE they do not overlap, they are very, very close, such that with normal resolutions they seem to overlap.

The legend_hfactor works, but it is somewhat inconsistent, because this does not work:

julia> plot(rand(10),label=L"2\pi")

julia> plot!(rand(10),label=L"2\pi")

julia> plot!(legend_hfactor=1.5,extra_kwargs=:subplot)

It is not completely clear where/when the keywords should work. Also, the extra_kwargs=:subplot is sort of a hack, and backend dependent. The main issue I see here is that this is a bad for first-impressions, and very inconvenient when using Plots for teaching. I would have never found this solutions except by searching for the bug itself.

@lmiq lmiq changed the title [BUG] overlap of labels with LaTeXStrings [BUG] labels are too close with LaTeXStrings Oct 18, 2021
@lmiq
Copy link
Contributor Author

lmiq commented Oct 18, 2021

Just a side comment:

If you or anyone else feels that this is not a bug, or the same bug, than any other, please feel free to close it. I just don't think that the alternatives we have are good enough for the time being.

@t-bltg
Copy link
Member

t-bltg commented Oct 18, 2021

The issue with adding some spacing is that it is subjective. That's why we do not add extra space as there is no consensus on what amount of default space to add (instead with GR we measure the maxima of all text heights, and use it to create the legend box). We provide backend dependent ways to add spacing and I think that this is the way to make everyone happy. To me this looks like a won't fix, but I'll leave this open if a majority wants to change this.

@t-bltg t-bltg added discussion and removed bug labels Oct 18, 2021
@lmiq
Copy link
Contributor Author

lmiq commented Oct 18, 2021

I agree that "how much" space is subjective. But the current status for legends which use LaTeXStrings is clearly not acceptable. See this, for example:

image

From: https://discourse.julialang.org/t/plots-jl-labels-overlap-if-using-latexstrings/69936

Since it is subjective, having "more" is probably safer than having "less" (with the possible complication that you can tell me that legend_hfactor < 1 would not be possible to use to reduce the spacing in that case).

@lmiq
Copy link
Contributor Author

lmiq commented Oct 18, 2021

Also note that the default is not working with LaTeXStrings. Without it, even with the same fonts, it works fine:

julia> plot([rand(10) rand(10)],labels=["ABC" "DEF"],fontfamily="Computer Modern")

image

While with LaTeXStrings, we get:

julia> plot([rand(10) rand(10)],labels=[L"\textrm{ABC}" L"\textrm{DEF}"])


image

Maybe the problem is somewhere else, in the recognition of the font height when using LaTeXStrings to apply the default label box size.

@t-bltg
Copy link
Member

t-bltg commented Oct 18, 2021

(with the possible complication that you can tell me that legend_hfactor < 1 would not be possible to use to reduce the spacing in that case).

I haven't checked it, but it should work (just a multiplicative factor of dy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants