BUG REPORT - Left Margin not working with Plots using PlotlyJS backend

It appears that when using the Plots package with the PlotlyJS backend, the left margin does not operate correctly.

Since the left and the bottom are where the Y and X axex reside, one would assume the margins should be applied in the same fashion for these, but right now they don’t.

The bottom works as expected: setting bottom_margin=some_number shifts the X axis title down by the specified distance so that there is white space between the axis numbers and the title.

When you set left_margin=some_number, however, it adds white space to the left of the title - not between the title and the Y axis numbers.

This makes for inconsistent and ugly looking plots, as there’s no way to make the X and Y axes match, except to play around with the bottom_margin until it nearly matches that of the left_margin.

For reference, I am running the LTS version of Julia 1.0.5 with updated packages. I also previously had the same experience with version 1.1 and due to other plotting issues I opted back to 1.0.5.

To demonstrate what I’m referring to, the following code produces the plots shown below.

# Load packages
using Plots
plotlyjs()
using Plots.PlotMeasures

# Data to plot
x = collect(Float64, 0:pi/100.:2.0*pi)
y = sin.(x)

# Font size and type
xyfont = font(36, "Times")
legfont = font(32, "Times")

# Figure/Plot image size
pixel_factor = 600
ps_x = pixel_factor * 3
ps_y = pixel_factor * 2
fig_size = (ps_x, ps_y)

# Axis properties
xprop = ("X Axis", (0, 2.0*pi), :none, :ln, :none, xyfont)
yprop = ("Y Axis", (-1.,  1.0), :none, :ln, :none, xyfont)

# Generate plot with margin=0mm
plot(
     x, y, label="sin(x)", xaxis=xprop, yaxis=yprop,
     size=fig_size,
     title="Plot 1 Margins: Default=0mm", 
     titlefont=xyfont,
     legendtitle="Legend", legend=:right, legendfont=legfont,
     framestyle=:box, color=:red, linestyle=:solid, linewidth=4,
     margin=0mm
    )
png("plot_1")

# Generate plot with margin=40mm
plot(
     x, y, label="sin(x)", xaxis=xprop, yaxis=yprop,
     size=fig_size,
     title="Plot 2 Margins: Default=40mm", 
     titlefont=xyfont,
     legendtitle="Legend", legend=:right, legendfont=legfont,
     framestyle=:box, color=:red, linestyle=:solid, linewidth=4,
     margin=40mm
    )
png("plot_2")

# Generate plot with margin=40mm, bottom_margin=15mm, left_margin=15mm
plot(
     x, y, label="sin(x)", xaxis=xprop, yaxis=yprop,
     size=fig_size,
     title="Plot 3 Margins: Default=40mm, Bottom=15mm, Left=15mm", 
     titlefont=xyfont,
     legendtitle="Legend", legend=:right, legendfont=legfont,
     framestyle=:box, color=:red, linestyle=:solid, linewidth=4,
     margin=40mm,
     bottom_margin=15mm,
     left_margin=15mm
    )
png("plot_3")

Results of Plot 1:

Results of Plot 2:

Results of Plot 3:

As you can clearly see from the plots, changing the margin values never changes the amount of white space between the Y axis title and the numbers, whereas for the X axis the margin controls work as expected and permit the user to provide ample white space to make the plot legible.

As one final example of how badly this can affect a real plot, take a look at the following:

In this plot the Y axis title is painfully close to the numbers along the axis and I have been unable to find any solution for this.

If there is already some fix, work-around, hack, etc. for any of this please let me know. Otherwise, I hope someone can provide a solution in a future release fairly soon.

I am not a Plots.jl user but I believe it will be very helpful if you would add some example plots showing the current behavior and the expected behavior. It would be also helpful if you add some minimal code to produce the plot where you encounter this problem.

Good point orialb. I updated the original post so it would all be in one place.

Bug-reports should go to the issue tracker of the package in question.

1 Like

mauro3, can you please provide a link to what you’re referring to? As best as I can recall, I have never had to report a bug before. Thanks.

1 Like

Here it is: https://github.com/JuliaPlots/Plots.jl/issues

Generally almost all packages are on github. Certainly all registered ones are on https://pkg.julialang.org, where there is a link to their code-repo as well.

It’s good form to first search the issues (best open and closed) to check that it has not been reported before.

1 Like

Thanks mauro3. I will leave this issue open for now in case anyone can suggest a work-around, but I have re-posted it in GitHub. While I did see some similar issues there, some had already been closed and were referencing other backends, so I felt this warranted a fresh post.

1 Like