Skip to content

Conversation

@t-bltg
Copy link
Member

@t-bltg t-bltg commented Jul 2, 2021

Fixes #3558:

  1. Fix height computation by retaining the maximum legend height, for each serie;
  2. Allow changing the height factor via the extra_kwargs mecanism.

Discussion:
Change [1.] does modify some reference images, but I think the fix is justified. Only applying [2.] allows fixing the OP issue, without changing the default legend sizes.

MWE

using LaTeXStrings
using Random; Random.seed!(1234)
using Plots; gr()

main() = begin
  y1, y2 = rand(100), rand(100)
  histogram(
    y1, ylims=(0, 50), label=L"\left\Vert\beta_{1}^{2}-\beta_{2}^{2}\right\Vert",
    extra_kwargs=Dict(:subplot=>Dict(:legend_hfactor=>1.25))
  )
  histogram!(y2, label=L"\left\Vert\beta_{2}^{2}-\beta_{3}^{2}\right\Vert", legendfontsize=10)
  png("foo")
end

main()

With PR

Without using extra_kwargs:
pr3

Using :legend_hfactor=>1.25:
pr3

Without PR

pr3

Default behavior modification (example # 23)

With PR

ref23

Without PR

ref23_old

Copy link
Member

@daschw daschw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@t-bltg
Copy link
Member Author

t-bltg commented Jul 2, 2021

@ptoche, is this approach ok for you ?

@t-bltg t-bltg changed the title Proposed fix for Latex strings in legends Proposed fix for Latex sub/super-scripts in legends Jul 2, 2021
@t-bltg t-bltg closed this Jul 2, 2021
@t-bltg t-bltg reopened this Jul 2, 2021
@t-bltg t-bltg closed this Jul 2, 2021
@ptoche
Copy link

ptoche commented Jul 3, 2021

This looks great, thanks for putting this together! :-)

@lmiq
Copy link
Contributor

lmiq commented Oct 17, 2021

I get still the same issue:

image

(jl_4g90hf) pkg> status GR
      Status `/tmp/jl_4g90hf/Project.toml`
  [28b8d3ca] GR v0.61.0

@t-bltg
Copy link
Member Author

t-bltg commented Oct 17, 2021

You can use legend_hfactor > 1 to fine tune the spacing.

@lmiq
Copy link
Contributor

lmiq commented Oct 17, 2021

That does not seem to have any effect on my plot. Am I doing something wrong?

image

Or isn't this released yet as of 0.61.0?

@t-bltg
Copy link
Member Author

t-bltg commented Oct 18, 2021

Please see the working example at #3598 (comment).

extra_kwargs are explained here.

This alternative also works:

using LaTeXStrings
using Random; Random.seed!(1234)
using Plots; gr()

main() = begin
  y1, y2 = rand(100), rand(100)
  histogram(y1, ylims=(0, 50), label=L"\left\Vert\beta_{1}^{2}-\beta_{2}^{2}\right\Vert")
  histogram!(
    y2, label=L"\left\Vert\beta_{2}^{2}-\beta_{3}^{2}\right\Vert", legendfontsize=10,
    legend_hfactor=1.25, extra_kwargs=:subplot
  )
  png("foo")
end

main()

@lmiq
Copy link
Contributor

lmiq commented Oct 18, 2021

Ok, thanks, so this MWE works:

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

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

The extra arguments have to be in the same plot! command as the second plot, otherwise it does not do anything (meaning, running plot!(legend_hfactor=1.5,extra_kwargs=:subplot) it not the way it works.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] control padding inside legend

5 participants