Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Formating titles and labels while using a faceted histogram

Hello everyone. Can I please ask for help in fixing a problem?

I’m faceting some histograms, but as you can see on the right, these titles are getting all bunched up. If you notice the graph, with 5 facets, both the left and right get too bunched up to look good.

Ideally I’d like the right hand side to be displayed right under each facet, and then the spacing between the facets to be enough for all the text to look right.

Here is the code I’m using to generate the faceted histograms, I’m using an ipywidget to change:

  • The feature
  • The color (label, only using categorical features)
  • The facet (using the same list as the labels)
# This widget allows you to create a faceted histogram
# You can interact with your chart by changing:
# 1. What feature you want to plot (via 'feature_names', a list of features in the dataframe)
# 2. What "color" you want to apply as a label (A list of categorical features in the dataframe)
# 3. What feature you want to facet (Using the categorical list)
@widgets.interact
def hist_inspect(feature = feature_names, label = labels, facet = labels):
    
    fig1 = px.histogram(df, 
                        x = feature,
                        color = label,
                        marginal = None, # can be 'rug', `box`, `violin`, 'histogram'
                        hover_data = df.columns,
                        color_discrete_map = {'Recovered': 'Green',
                                              'Active': 'Yellow',
                                              'Died': 'Red',
                                              'Male': 'Blue',
                                              'Female': 'Pink',
                                              'Unkonwn': 'Fucha',
                                             },
                        color_discrete_sequence = px.colors.qualitative.Antique,
                        facet_row = facet,
                        #title = General_title,
                        #width = 1200, 
                        #height = 2500
                        )
    
    fig1.update_layout(title = General_title,
                       font = dict(family = "Courier New, monospace",
                                   size = 15,
                                   color = "Black"
                                  )
                      )
    fig1.show()

The code works great! I just need to fix some formatting and it’ll be good to go!

I’d really appreciate any help in fixing.

Cheers!