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

Subplots #206

Closed
pkozela opened this issue Sep 17, 2016 · 12 comments
Closed

Subplots #206

pkozela opened this issue Sep 17, 2016 · 12 comments
Milestone

Comments

@pkozela
Copy link

pkozela commented Sep 17, 2016

Hi guys,

any plans to add the ability to generate multiple charts ? (matplotlib's subplot equivalent)

PS. This project is just amazing !

@jakevdp
Copy link
Collaborator

jakevdp commented Sep 17, 2016

Yes! This feature will be supported by Vega Lite in the upcoming release, and we'll have Altair bindings for it as soon as possible once that's available.

@kanitw
Copy link
Member

kanitw commented Oct 3, 2016

You can also use row and column channel to encode your partition field. (But we do not support wrapped trellis / subplots yet.)

@jakevdp jakevdp added this to the 2.0 milestone Nov 2, 2016
@simonm3
Copy link

simonm3 commented Dec 10, 2016

+1 this is a really great project.

Re subplots , matplotlib requires you specify the layout in advance and the grid coordinates for each chart. One thing I do a lot is to call multiple functions which collectively show 20-40 unrelated charts. I don't know the layout in advance as I don't know how many charts I will have in total; and within a function when I print a chart I don't have the context so I don't know the position in the grid.

I just know that 10 rows of 4 charts is neater than a big long list of 40 charts. So I want a one liner to start "gridprint"; and then all subsequent charts take the next place in the grid. Would be great if you could do that.....Maybe this is in the vega spec but could not see it.

@ellisonbg
Copy link
Collaborator

Closing as vega-lite-related

@ronyarmon
Copy link

Seaborn has a one-liner for subplots, no need to specify layout.
Altair/vega-lite is great but similar functionaliy will be helpful

seaborn_subplots.txt

@jakevdp
Copy link
Collaborator

jakevdp commented May 30, 2018

Altair does create these kinds of faceted subplots automatically. If you take the above dataframe and put it into the long-form format used by Altair, it can be done with a straightforward set of encodings:

import altair as alt

# Make data long-form
data = diff_ccgs.melt().reset_index()

alt.Chart(data).mark_line().encode(
    x='index',
    y='value',
    color='variable',
    column='variable'
)

@ronyarmon
Copy link

Thanks, but reset_index, which is necessary for melting here, is an issue as the data is an excerpt from a time series.

@jakevdp
Copy link
Collaborator

jakevdp commented May 30, 2018

Why is that an issue? If you want the index to be on the x axis, you need to make it an explicit column (using reset_index). It doesn't matter what the type of the index is.

@jakevdp
Copy link
Collaborator

jakevdp commented May 30, 2018

If the index is named, then it will keep its original name rather than being called index.

@jakevdp
Copy link
Collaborator

jakevdp commented May 30, 2018

You might need to switch the order in order to keep the index; e.g.

diff_ccgs.reset_index().melt('index')

The point is to get whatever data you want to plot into the appropriate long-form representation. The pandas manipulations are up to you 😄

@ronyarmon
Copy link

You're right, no issues! (I tried pd.melt but your line worked better). However, I'm getting the charts in a long row so to come back to the matplotlib-like question, can we specify a layout? I also draw many plots and want them say in a 2 * 5 layout.

@jakevdp
Copy link
Collaborator

jakevdp commented May 31, 2018

It can be done, but not easily (you can transform the data in order to generate new encodings that map to the rows & columns you want).

It will be much easier when wrapped facets land in Vega-Lite; see vega/vega-lite#393 to track progress on that.

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

No branches or pull requests

6 participants