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

Titles after vstack/hstack #600

Closed
tcovert opened this issue Jun 1, 2015 · 13 comments · Fixed by #937
Closed

Titles after vstack/hstack #600

tcovert opened this issue Jun 1, 2015 · 13 comments · Fixed by #937

Comments

@tcovert
Copy link

tcovert commented Jun 1, 2015

Is it possible to add titles to a grid of figures? Say I've got plots p1-p4, and I combine them and render to a PDF (as in the documentation):
draw(PDF("file.pdf",6inch,6inch),vstack(hstack(p1,p2),hstack(p3,p4))

I see that its possible to add titles to each of the individual plots, but how would I add a title above (or below) the grid of p1-p4?

@dcjones
Copy link
Collaborator

dcjones commented Jun 1, 2015

There's not any special support for this, but it's possible to do "manually" through Compose:

p = hstack(plot(x=rand(50), y=rand(50), Geom.point),
           plot(x=rand(50), y=rand(50), Geom.point))
title = compose(context(0, 0, 1w, 0.25inch),
                text(0.5, 1.0, "These are some plots", hcenter, vbottom))
vstack(title, p)

try

@tcovert
Copy link
Author

tcovert commented Jun 1, 2015

Thanks, this is great. I assume I need to add "using Compose" to the top of my code?

@dcjones
Copy link
Collaborator

dcjones commented Jun 1, 2015

Oh, right. You do need using Compose.

@tcovert
Copy link
Author

tcovert commented Jun 1, 2015

is there documentation for the compose() and text() functions somewhere? I didn't see it on composejl.org

@IainNZ
Copy link
Contributor

IainNZ commented Jun 1, 2015

Those are the docs right now, plus the source itself

The all-important function in Compose, is called, not surprisingly, compose. Calling compose(a, b) will return a new tree rooted at a and with b attached as a child.

@dcjones
Copy link
Collaborator

dcjones commented Jun 1, 2015

There's unfortunately not API documentation for things like text.

@protogeezer
Copy link

What's the best way to handle the case of an odd number of plots? In other words, how would one leave a blank on one side of the "bottom" row?

@protogeezer
Copy link

FWIW, here is my best shot. I couldn't figure out how to specify font attributes other than family and size. Creating an all white plot is a bit crude, but it does seem to work.

        title1 = compose(context(0, 0, 1w, 0.2h),font("Times"),fontsize(24pt), text(0.5, 1.0, 
                                     "The first line of the title", hcenter, vbottom))
    title2 = compose(context(0, 0, 1w, 0.05h),font("Helvetica"),fontsize(14pt), text(0.5, 1.0, 
                                     "This is the stuff you don't want anyone to notice", hcenter, vbottom))
    blank = plot(x=1:10,y=1:10,Geom.point,
                    Theme(default_color=colorant"white",
                                grid_color=colorant"white",
                                minor_label_color=colorant"white",
                                major_label_color=colorant"white"))
    p = plot(x=collect(1:10), y=collect(1:10), Geom.point);
    draw(PDF("test.pdf",8inch,11inch),vstack(title1,title2,hstack(p,p),hstack(p,p),hstack(p,blank)))

test

@dcjones
Copy link
Collaborator

dcjones commented Oct 19, 2015

That's pretty good. Another way to go about this is with gridstack.

using Gadfly, Compose

M = Array(Compose.Context, (2,2))
M[1,1] = render(plot(x=rand(10), y=rand(10)))
M[1,2] = render(plot(x=rand(10), y=rand(10)))
M[2,1] = render(plot(x=rand(10), y=rand(10)))
M[2,2] = context()
gridstack(M)

try

It might be worth trying to make this sort of thing simpler.

@protogeezer
Copy link

contex()? Are you kidding me! This is great. The example I came up with reduces to:

...
gs = gridstack(M);
draw(PDF("test.pdf",8inch,11inch),vstack(title1,title2,gs))

For some reason, yesterday vstack was complaining about not accepting a type “Table”.

For sure, it is worth making laying out a group of plots easier.

What I’d belly up to is building on the MatPlotLib model of declaring grids and then allocating rectangular blocks of the grid either to a single plot or another grid. I could also imagine being able to assign a few parameters to each grid - maybe a title and a border of some sort. The purpose of the grid is to provide a sense of relative size - without the need for relative (i.e. unit) coordinates.

I don’t know yet whether it would make sense to finish some of the other work we’ve discussed before diving into something like this which would, admittedly, be fun…

Stephen

On Oct 19, 2015, at 1:45 PM, Daniel C. Jones [email protected] wrote:

That's pretty good. Another way to go about this is with gridstack.

using
Gadfly, Compose

M = Array(Compose.Context, (2,2))
M[1,1] = render(plot(x=rand(10), y=rand(10)))
M[1,2] = render(plot(x=rand(10), y=rand(10)))
M[2,1] = render(plot(x=rand(10), y=rand(10)))
M[2,2] = context()

gridstack(M)

It might be worth trying to make this sort of thing simpler.


Reply to this email directly or view it on GitHub.

@davidanthoff
Copy link

The example by @dcjones (first response) actually cuts of the x labels from the plots. Any idea how to get them showing?

@CorySimon
Copy link

+1, this shared title solution cuts off the x-axis labels...

@Mattriks
Copy link
Member

Try relative not absolute sizes (see also #656).
For example:

using Compose

pa = hstack(plot(x=rand(50), y=rand(50), Geom.point),
           plot(x=rand(50), y=rand(50), Geom.point))
title = compose(context(0, 0, 1, 0.1),
                text(0.5, 1.0, "These are some plots", hcenter, vbottom))
p = vstack(title, compose(context(0, 0, 1, 0.9), pa))

Note that the output of hstack() is of type Compose.Context.

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 a pull request may close this issue.

7 participants