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

Showing HTML of two plots generated with to_html fails #3436

Open
augustebaum opened this issue Jun 14, 2024 · 0 comments
Open

Showing HTML of two plots generated with to_html fails #3436

augustebaum opened this issue Jun 14, 2024 · 0 comments
Labels

Comments

@augustebaum
Copy link

augustebaum commented Jun 14, 2024

What happened?

See screenshots, along with the following snippet to reproduce.
I have a slight suspicion this is related to #3435.

With to_html:
2024-06-14T16_32_30_screenshot

Without to_html:
2024-06-14T16_32_37_screenshot

import altair as alt
import numpy as np
import pandas as pd
from altair.utils._show import open_html_in_browser

A = np.array([[50, 0, 0], [0, 48, 2], [0, 2, 48]])

data = pd.DataFrame(
    ((i, j, v) for (i, j), v in np.ndenumerate(A)), columns=["i", "j", "v"]
)
chart = (
    alt.Chart(data, title="Confusion matrix")
    .mark_rect()
    .encode(
        x=alt.X("i:O", axis=alt.Axis(orient="top"), title="Predicted class"),
        y=alt.Y("j:O", title="True class"),
        color="v:Q",
    )
    .properties(width=400, height=400)
)

# only shows one plot
open_html_in_browser(f"{chart.to_html()} {chart.to_html()}")


def altair_to_html(chart):
    from altair.vegalite.v5.display import html_renderer

    return html_renderer(chart.to_dict())["text/html"]


# correctly shows 2 plots
open_html_in_browser(f"{altair_to_html(chart)} {altair_to_html(chart)}")

What would you like to happen instead?

Both methods should have the same behavior.

Which version of Altair are you using?

5.3.0

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

No branches or pull requests

1 participant