mckinsey / vizro

Vizro is a toolkit for creating modular data visualization applications.

Home Page:https://vizro.readthedocs.io/en/stable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple Series Line Chart Updates

mkretsch327 opened this issue · comments

Description

When creating a line chart with multiple series, I've noticed it's not possible to update the legend and y_axis titles (potentially more). If specifying a single series, the titles are updated and represented accordingly.

Expected behavior

I'd expect to be able to update the y_axis title and potentially also the legend titles when passing multiple column names (as a python list) to a px.line call, as can be done with dash.

Which package?

vizro

Package version

0.1.16

Python version

3.10.14

OS

Ubuntu 20.04

How to Reproduce

Code to reproduce the behavior I'm observing

from vizro import Vizro
import vizro.plotly.express as px
import vizro.models as vm

df = px.data.stocks()

page = vm.Page(
    title="My first dashboard",
    components=[
        vm.Graph(id="scatter_chart", figure=px.line(df, x="date", y=["GOOG", 'AAPL']).update_layout(yaxis_title='New Y-axis', legend_title='new legend')),
    ]
)

dashboard = vm.Dashboard(pages=[page])

Vizro().build(dashboard).run()

Output

Sharing here the resulting dashboard view, titles are not being updated even though updates are specified.
image

Code of Conduct

Hey @mkretsch327 ,

for all post-update calls you currently need to use our chart decorator to create a custom chart. See our documentation on custom charts.

In your case, it would look like this:

from vizro.models.types import capture

@capture("graph")
def custom_line(data_frame, x, y): 
    fig = px.line(data_frame, x=x, y=y)
    fig.update_layout(yaxis_title='New Y-axis', legend_title='new legend')
    return fig

And then you can insert the custom_line figure as usual:

vm.Graph(id="scatter_chart", figure=custom_line(df, x="date", y=["GOOG", 'AAPL']))

Hope that helps! :) And let me know if you have any suggestions on the docs, maybe we have to make this clearer so it's easier to find! @stichbury

@huong-li-nguyen Thanks so much! This is helpful and solved it :) .BTW great work on this!