简体   繁体   中英

Plotly v5.3.1 combined count histogram and KDE curve

I currently have this code:

import dash_core_components as dcc #dash version 2.0.0
import plotly.figure_factory as ff #plotly version 5.3.1

...dash app code

dcc.Graph(id = 'rug_plot_count_region_biosynthetic_protein_homologs',
          figure = ff.create_distplot([filtered_df['count_region_biosynthetic_protein_homologs'].tolist()], 
                                      group_labels = ['count_region_biosynthetic_protein_homologs'])),

...more dash app code

Which makes this figure, as part of a dash app:

情节分布图

I'd like to have two y-axis, one showing the probability density for the KDE curve (which is the y-axis already there) and one showing the count frequency. I'd then like the KDE curve to be linked to the KDE y-axis and the histogram to be linked to the count y-axis.

Is there a way to do this using plotly?

Thanks for reading!

Tim

  • you can replace the histogram or normal distribution with standard histogram
  • focus on building figure before integrating into dash
  • can't find any sample data for your domain, so have used random
import plotly.figure_factory as ff
import plotly.express as px
import numpy as np
import pandas as pd

np.random.seed(1)

filtered_df = pd.DataFrame({"count_region_biosynthetic_protein_homologs": np.random.randn(1000)})

fig = ff.create_distplot(
    [filtered_df["count_region_biosynthetic_protein_homologs"].tolist()],
    group_labels=["count_region_biosynthetic_protein_homologs"],
    show_hist=False,
).add_traces(
    px.histogram(filtered_df, x="count_region_biosynthetic_protein_homologs")
    .update_traces(yaxis="y3", name="histogram")
    .data
).update_layout(yaxis3={"overlaying": "y", "side": "right"}, showlegend=False)

fig

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM