Bug in Plots.jl - Unwanted line in the title with multi-column legend

MWE:

Pkg.add(“PlotThemes”)
Using Plots, DifferentialEquations, ModelingToolkit, LaTeXStrings, Symbolics, Measures
theme(:bright)
plot(sol, label = L"some \ \LaTeX“, xlabel = L”t“, ylabel = L”\alpha“, margin=8mm, framestyle = :box)
plot!(plot_title = “XYZ \n ABC”, titlefontsize = 15, legendposition = :bottomleft, legendfontsize = 12, legend_column = 2, legend_foreground_color = “black”)
plot!(sol.t, t-> sin(t), label = L”some \ more\ \LaTeX")

The above code plots perfectly - it looks great too, except for a horizontal black coloured line right at the top (just beside the plot title). I have noticed that this problem only occurs if I use a multi-column legend (which I need to in this case because my labels are too large).

As an example, I have attached the problematic part below:

Good that you provide code, though to make it easier to help there are a few things you could think about in the future.

What you provide is not really an MWE (minimal working example) as it is neither minimal nor working in the provided state.

A minimal example is nice since it reduces the surface area for the problem, and it is easier for people to get an understanding what the involved parts are. Here I’m not sure if the problems could be the PlotThemes package, the Plots package, or maybe something with LaTexStrings? Or maybe it is even something with DifferentialEquations, though that seems less plausible.

A working example is obviously easier to try out, not having to figure out what kind of things you are plotting and if it needs to be some specific data for the problem to occur. I can’t just try to run this code as it does not provide the sol to be plotted.

It is also nicer to use the code blocks (preformatted text in the discourse ui) instead of blockquotes as it makes it easier to read and also makes the code more friendly to copy. Currently the quotation marks are replaced with fancy non-programming ones when I copy the code, and I have to replace them to be able to run anything.

Hope that didn’t come off as whiny, just want to help people get better help :slight_smile:

For this case it wasn’t too hard to just remove some stuff and make up some data, so here is something I would consider a better MWE running on Julia 1.9.1 using Plots v1.38.15

julia> using Plots

julia> plot(0:0.01:3, [sin, cos])

julia> plot!(plot_title="XYZ", legendposition=:bottomleft, legend_column=2)

Removing the plot_title or legend_column removes the problem, removing legendposition moves the extra line to a different position. Plotting and setting the values in the same call does not show the problem, so it is something with doing it in two steps that causes it.

With that said, I don’t really know the internals of Plots so I don’t really have much more help to give :sweat_smile:
But it seems like a bug to me, so you could check the issues on github and add it if you can’t already find it there.

1 Like

This bug seems to occur when you ask to plot both the title and the multi-column legend in the same plot command.

If you leave the plot title aside as the last command, the spurious line disappears. See edited MWE :

using Plots, LaTeXStrings, Measures

plot(sin, label=L"some\ LATEX", xlabel=L"t", ylabel=L"α", margin=8mm, framestyle=:box)
plot!(cos, label=L"some\ more\ LATEX", ylims=(-1.6,1.1))
plot!(leg=:bottomleft, legendfontsize=12, legend_column=2, fg_legend="black")
plot!(plot_title="XYZ\nABC", titlefontsize=15)
1 Like

Thanks for the help! Sorry for the poor MWE but my original code was too large (also, this 2 column thing was something new I just tried today - the rest of the thing has been working well for the past few months so I figured whatever was wrong would be in the plot() command). Thanks again!

1 Like