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

(WIP) Clustering allows mw #2454

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

(WIP) Clustering allows mw #2454

wants to merge 5 commits into from

Conversation

RobinL
Copy link
Member

@RobinL RobinL commented Oct 7, 2024

import altair as alt
import pandas as pd

# Assuming 'dc_df' is your DataFrame
# dc_df = pd.DataFrame({...})

# Define the options for the x-axis
x_axis_options = ['threshold_match_probability', 'threshold_match_weight']

# Create a selection parameter with radio buttons
x_axis_param = alt.param(
    name='x_field',
    bind=alt.binding_radio(options=x_axis_options, name='X-axis: '),
    value='threshold_match_probability'
)

# Base chart with dynamic x-axis based on the parameter
base_chart = (
    alt.Chart(dc_df)
    .transform_fold(
        fold=['threshold_match_probability', 'threshold_match_weight'],
        as_=['variable', 'x_value']
    )
    .transform_filter(
        alt.datum.variable == x_axis_param
    )
    .add_params(x_axis_param)
    .encode(
        x=alt.X('x_value:Q', title='X-axis')
    )
    .properties(width=400, height=150)
)

# Define the subcharts
num_clusters = (
    base_chart.mark_line()
    .encode(
        y=alt.Y("num_clusters:Q", title="Number of Clusters")
    )
    .properties(title="Number of Clusters vs X-axis")
)

max_cluster_size = (
    base_chart.mark_line()
    .encode(
        y=alt.Y("max_cluster_size:Q", title="Max Cluster Size")
    )
    .properties(title="Maximum Cluster Size vs X-axis")
)

avg_cluster_size = (
    base_chart.mark_line()
    .encode(
        y=alt.Y("avg_cluster_size:Q", title="Average Cluster Size")
    )
    .properties(title="Average Cluster Size vs X-axis")
)

# Combine the charts
combined_chart = alt.vconcat(
    num_clusters, max_cluster_size, avg_cluster_size
).resolve_scale(y="independent")



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

Successfully merging this pull request may close these issues.

1 participant