Hello everyone! I'm facing an issue regarding Kedr...
# questions
l
Hello everyone! I'm facing an issue regarding Kedro-Viz experiment tracking. I want to report results of a PCA decomposition in a Plotly graph. I prototyped the node that draws the plot in a notebook with some styling (mainly a centered title and a square aspect-ratio) with results displayed in the first image. Happy with the results I ported everything into a node that outputs the figure to a
plotly.JSONDataSet
. The pipeline runs fine, the plot is saved to disk and displayed in the experiment tracking section but the styling applied in the
fig.update_layout()
call seem to be skipped as you can see from the second image. Everything else is displayed as desired (included menu and hover data). Any clue on what could be the issue here? This is the code present in the node that outputs it:
Copy code
def plot_loadings(loadings: NDArray) -> go.Figure:
    fig = go.Figure(layout_yaxis_range=[-1, 1], layout_xaxis_range=[-1, 1])

    fig.add_traces(
        go.Scattergl(
            x=loadings[:, 0],
            y=loadings[:, 1],
            mode="markers",
            hovertext=[f"Var{i+1}" for i in range(loadings.shape[0])],
        )
    )

    x_buttons = []
    y_buttons = []

    for i in range(loadings.shape[1]):
        x_buttons.append(
            dict(
                method="update",
                label=f"PC{i + 1}",
                args=[
                    {"x": [loadings[:, i]]},
                ],
            )
        )

        y_buttons.append(
            dict(
                method="update",
                label=f"PC{i + 1}",
                args=[
                    {"y": [loadings[:, i]]},
                ],
            )
        )

    fig.update_layout(
        updatemenus=[
            dict(buttons=x_buttons, direction="up", x=0.5, y=-0.1, active=0),
            dict(
                buttons=y_buttons,
                direction="down",
                x=-0.01,
                y=0.5,
                active=(1 if loadings.shape[1] > 1 else 0),
            ),
        ]
    )

    fig.update_layout(
        {
            "title": {"text": "Loadings Plot", "x": 0.5},
            "width": 1000,
            "height": 1000,
        }
    )

    return fig
d
cc @Tynan one for you if you have any ideas?
t
interesting. i'm not sure why those
update_layout
calls aren't working as expected. have you looked at the contents of the output JSON file for this plot? does it contain your
"Loadings Plot"
title text?
l
Yes it does! The json file ends with (omitting what is before):
"direction":"down","x":-0.01,"y":0.5}],"title":{"text":"Loadings Plot","x":0.5},"width":1000,"height":1000}}
t
got it. would you mind please sending the entire contents of the file?
l
Sure thing
👍 1
pca_laodings_plot.json
(Disregard any prototype-level laziness in naming 😛 )
t
haha, will do
have some meetings this afternoon and will turn to looking into this again afterwards
just to clarify: you want the second screenshot to look like the first, correct?
👍 1
l
No worries, as I said the plots are correctly displayed in the Experiment Tracking tab and they are functional/displayable. The only issue is that looks like some of styles get overridden.
👍 1
Yes, that's correct
t
got it
hey Lorenzo, sorry for the delay here. the reason your custom overrides aren't working is because a lot of the styles for Ploty charts in Viz come from config files (like this one). so no matter what you do, if the specific style you're trying to set is present in our config, then it won't have any effect
👍 1
l
That's mildly annoying but I understand the reasoning! Thanks for looking into it!
👍 1
t
anytime