I have an application that begs for building a row (or grid) of charts inside a for loop where the iterated value might a column label in the pandas dataframe. I've read the documentation for hconcat and repeat methods and repeat is well suited to this, however, my application demands that each chart contain an overlay of data from two different dataframes which (I think) precludes the use of the repeat function. Is there anyway to iteratively build a list a charts within the for loop and then display them in a row or grid after the loop is done executing?
Thanks in advance!
I think it's possible to do what you're asking about, but it's hard to say without more information.
Regarding the repeat operator and multiple dataframes, you could use the lookup transform if it applies to the way you're combining the multiple dataframes.
Otherwise, you can always use a Python loop to create multiple charts, and then concatenate them when finished. Something like this:
charts = []
for i in range(4):
charts.append(alt.Chart(df).mark_point())
alt.vconcat(*charts)
Hi Jake,
Super helpful information - thanks! I will give that a try.
-Dave
PS - I am giving some presentations to university computer science and engineering departments in the Northeast in the coming months (Dartmouth and Lehigh to start) and will be mentioning altair as one of the exciting new packages to investigate. Please keep up the awesome work!
Thanks, and let me know if you have other questions!
Your tip worked great - thank you!
Now if only plot interactivity was preserved after converting a notebook to html format.......
-Dave
@dbk123 see this for a workaround to maintain interactivity in HTML
Thanks!
Most helpful comment
I think it's possible to do what you're asking about, but it's hard to say without more information.
Regarding the repeat operator and multiple dataframes, you could use the lookup transform if it applies to the way you're combining the multiple dataframes.
Otherwise, you can always use a Python loop to create multiple charts, and then concatenate them when finished. Something like this: