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

Clustergram: Set min and max for colorscale #709

Open
ethantenison opened this issue Sep 9, 2022 · 1 comment
Open

Clustergram: Set min and max for colorscale #709

ethantenison opened this issue Sep 9, 2022 · 1 comment

Comments

@ethantenison
Copy link

I'm trying to creating a clustergram using a correlation matrix, and I'd like the color scale to be from -1 to 1 regardless of what is present in the data. Without manually setting it the results can be deceiving visually.

In the plotly go heatmap you set it by specifying zmin and zmax, but I don't see an equivalent from the clustergram documentation here.

Here's what my clustergram looks like:
newplot (36)

You can see that the color scale cuts off at around 0.35.

@adkinsrs
Copy link

A while back, I implemented a workaround to address some heatmap colorings for our own application

    fig = dashbio.Clustergram(
        data=values
        , column_labels=col_labels
        , row_labels=row_labels
        , hidden_labels=hidden_labels
        , cluster=cluster
        , col_dist=col_dist
        , row_dist=row_dist
        , center_values=center_around_zero
        , color_map=colorscale
        , display_ratio=0.3                 # Make dendrogram slightly bigger relative to plot
        , line_width=1                      # Make dendrogram lines thicker
        , log_transform=False if is_log10 else True
    )

    fig.data[-1]["reversescale"] = reverse_colorscale

    if center_around_zero:
        fig.data[-1]["zmid"] = 0
    else:
        # both zmin and zmax are required
        fig.data[-1]["zmin"] = 0
        fig.data[-1]["zmax"] = max(map(max, fig.data[-1]["z"])) # Highest z-value in 2D array
        
      # do extra stuff and return "fig"

Basically in the returned clustergram figure (fig), the last element in fig.data is the heatmap and you can change the heatmap properties. For this example, the color range will be set depending on if we want to center the expression values around zero or not.

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

No branches or pull requests

2 participants