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

plot_title kwarg is ignored #2587

Closed
kalmarek opened this issue Apr 16, 2020 · 5 comments · Fixed by #2690
Closed

plot_title kwarg is ignored #2587

kalmarek opened this issue Apr 16, 2020 · 5 comments · Fixed by #2690
Labels
extension new behaviour

Comments

@kalmarek
Copy link

kalmarek commented Apr 16, 2020

MWE:

plotgrid = plot(plot(x->x^2, title="f(x) = x²"), plot(x->sin(x), title="f(x) = sin(x)"), 
    layout=grid(1,2), link=:y, plot_title = "Some functions")

EDIT:
oh, sorry, just found out that the attribute is (Note: Not currently implemented).

any workaround how to add a global title to grid of sub-plots?

@BeastyBlacksmith
Copy link
Member

That depends on the backend used. Generally one can add an empty subplot that only has a title at the top of the layout.
In the pgfplotsx-backend you can also use an annotation, but finding the right coordinates is a bit of trial and error, might also work for other backends, but not sure.

@BeastyBlacksmith BeastyBlacksmith added the extension new behaviour label Apr 16, 2020
@BeastyBlacksmith
Copy link
Member

I actually started implementing it in #2363 (without the backend implementations though)

@fbanning
Copy link

Ahoy, what's the current status of this issue? We would be very interested in using the plot_title kwarg for our plots without having to use a workaround. Thanks for any updates in advance, best wishes.

@bgroenks96
Copy link

Could someone post a code example for a workaround, like the empty plot thing?

The example provided here kind of works, but it's a bit ugly since you can still the see the plot in the background of the title...

@TheCedarPrince
Copy link

Hey @BeastyBlacksmith and Plots.jl team! Great work here! I was just wondering, what is the status on this issue? As @bgroenks96 pointed out, there was a bit of a hack that I am using as well. Here is an example of me working around this issue that looks something like this (the code is not too pretty!):

using DataFrames
using Plots

df = rand(5, 5) * 10 |> DataFrame

function pairplot(df)
    rows, cols = size(df)
    y = ones(3)
    title = Plots.scatter(
        y,
        marker = 0,
        markeralpha = 0,
        annotations = (2, y[2], Plots.text("Pair plot")),
        axis = ([], false),
        leg = false,
        size = (200, 100),
    )
    plots = []
    for row = 1:rows, col = 1:cols
        if row == rows && col == 1
            push!(
                plots,
                scatter(
                    df[row],
                    df[col],
                    xtickfont = font(4),
                    ytickfont = font(4),
                    legend = false,
                    xlabel = "foo",
                    xguidefontsize = font(4),
                    ylabel = "bar",
                    yguidefontsize = font(4),
                ),
            )

        elseif row == rows
            push!(
                plots,
                scatter(
                    df[row],
                    df[col],
                    xtickfont = font(4),
                    ytickfont = font(4),
                    legend = false,
                    xlabel = "foo",
                    xguidefontsize = font(4),
                ),
            )
        elseif col == 1
            push!(
                plots,
                scatter(
                    df[row],
                    df[col],
                    xtickfont = font(4),
                    ytickfont = font(4),
                    legend = false,
                    ylabel = "bar",
                    yguidefontsize = font(4),
                ),
            )
        else
            push!(
                plots,
                scatter(
                    df[row],
                    df[col],
                    xtickfont = font(4),
                    ytickfont = font(4),
                    legend = false,
                ),
            )
        end
    end
    plot(
        title,
        plot(plots..., layout = (rows, cols)),
        layout = grid(2, 1, heights = [0.05, 0.95]),
    )
end

pairplot(df)

Which produces this image:

image

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

Successfully merging a pull request may close this issue.

5 participants