-
Notifications
You must be signed in to change notification settings - Fork 1k
Add Altair plotting functionality #2810
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
base: main
Are you sure you want to change the base?
Conversation
Performance benchmarks:
|
@Sahil-Chhoker I really like the set up its very smooth and plot component will be easy to adopt for users. What I did, I implemented boltzmann wealth and sugarscape from the examples using altair. A couple things:
For the altair space this make spice the title of the render. This is just an indicator of behavior that I hope is useful as you continue to refine the code. I really look how this is coming together, let me know what you think. |
Done.
Just don't call
Will look into this, thanks for telling. |
@tpike3, I've addressed all the comments, feel free to let me know if you find anything else concerning. |
Buffer between plots?
I will need to modify this function in the def make_initial_grid_layout(num_components):
"""Create an initial grid layout for visualization components.
Args:
num_components: Number of components to display
Returns:
list: Initial grid layout configuration
"""
return [
{
"i": i,
"w": 16,
"h": 16,
"moved": False,
"x": 6 * (i % 2),
"y": 16 * (i - i % 2),
}
for i in range(num_components)
] I will experiment with this a little and try to come up with something usable.
New page can definitely be possible, but first I would love to discuss the API interface for it, I'm thinking something like this: plot_component = make_plot_component(..., page=1)
# and if the page number is too big like page=20, it will default to the last existing page, like 1 Altair plots
Sometimes I get unnecessary errors that go away be reloading the page, but I didn't get this kind of error. Maybe share the contents of the error. Syntax for customizationmodel = SugarscapeG1mt()
renderer = SpaceRenderer(model, backend="altair")
# to skip drawing structure
renderer.draw_agents(agent_portrayal)
renderer.draw_propertylayer(propertylayer_portrayal)
# to customize grid
renderer.render(agent_portrayal, propertylayer_portrayal, space_kwargs={
"xlabel": "x",
"ylabel": "y",
"grid_color": "blue",
"grid_dash": [6, 2],
"grid_width": 4,
"grid_opacity": 0.5,
}) # or just pass these arguments directly in draw_structure
# for more control:
def post_process(chart):
chart = chart.properties(...) # or something else
return chart
renderer.post_process = post_process
# Note: The customizability for sugerscape is very limited because of how the colorbars are handled
# in the chart and similarly the customizability is different for every space.
# To customize grid every detail is mentioned in the respective `space_drawer` docstring.
# To customize plots:
def post_process_plot(chart):
chart = chart.(...)
return chart
plot_component = make_plot_component("#Traders", backend="altair", grid=False, post_process=post_process_plot)
page = SolaraViz(
model,
renderer,
components=[
plot_component,
make_plot_component("Price"),
],
model_params=model_params,
name="Sugarscape {G1, M, T}",
play_interval=150,
)
page |
For this----
You were correct, I went to re run it and I did not get the same error, so it must have been some artifact of me trying different things. Switching to Altair for the plots I did get this warning:
Just for your awareness. |
@tpike3, just a report, I am currently reworking how property layers are drawn in altair, the current version is very unstable. |
Thanks for the update! Let me know if I can help out in anyway |
Summary
Adds the functionality to make plots using altair.
Motive
Part of my GSoC commitment.
Implementation
Following the design of matplotlib plotting function, a
make_altair_plot_component
function is made that returns a callable solara componentPlotAltair
.Additional kwarg is
grid: bool
, used to draw grid on the plot, default is False.Usage Examples
How it looks: