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

Stack plots and align axes #1455

Open
CiaranOMara opened this issue Jun 15, 2020 · 3 comments
Open

Stack plots and align axes #1455

CiaranOMara opened this issue Jun 15, 2020 · 3 comments

Comments

@CiaranOMara
Copy link
Contributor

Is there a way to stack different types of plots and align their axes?

I'm trying to construct one column from something like the following.

Related: #619, #1169

@Mattriks
Copy link
Member

Mattriks commented Jun 15, 2020

Currently here's no automated way to do this. The easiest workaround would be to use Theme(plot_padding=[l, r, t, b]). See ?Theme

The main development of this feature would be done in Compose. E.g.

using Compose
ct1 = compose(context(0,0,1,1), fillopacity(0.0), 
#    (context(), rectangle(), stroke("silver")),
    (context(0,0, 0.9,0.2), rectangle(), stroke("orange")),
    (context(0,0.2, 1.0,0.8), rectangle(), stroke("blue"))
)

The design idea is to extract the layout from ct1, and apply the same layout (horizontally or vertically) to someother compose tree ct2.

@CiaranOMara
Copy link
Contributor Author

In a vstack, it seems that the plot_padding would need to be adjusted for bottom halves with different heights.

I'm keen to try the compose route. In terms of laying out the receiving tree, is there a way to pin the width of a context and let its height be relative or does an aspect ratio need to be calculated in advance?

# Core plots.
M = rand(200, 100)
p1 = plot(Geom.line, x = collect(axes(M,2)), y = sum.(eachcol(M)))
p2 = spy(M, Guide.yticks(ticks=[], label=false))
# Context splicing.
r1  = render(p1)
r2  = render(p2)

table1 = r1.container_children.head.container_children.head.children
table2 = r2.container_children.head.container_children.head.children

ctx = compose(context(0,0,1,1), fillopacity(0.0),
    (context(0, 0,    1.0, 0.2), Compose.rectangle(), Compose.stroke("orange"), table1[7]), # WIP
    (context(0, 0.2, 1.0, 0.8), Compose.rectangle(), Compose.stroke("blue"), table2[1], table2[2]) # WIP
)

@Mattriks
Copy link
Member

In the case of your plot above, yes I should have said use Theme(plot_padding= ) with vstack2 in #1169.

Same for my design idea, you would need to combine: extracting the layout, applying it to the other plot, and stacking the 2 plots, all in one function. The function should also allow you to manually adjust the layout in the non-aligned direction. Currently Gadfly plots don't store information about their absolute size (#1299), but adding knowledge of plot size to an individual plot also might be useful here.

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

No branches or pull requests

2 participants