Question:
How to adjust the size of marginal distribution plots in Plotly Express?

Problem:

I have several datasets I am plotting with plotly express's scatterplot. I am using the option of the marginal distribution plots to show a histogram of the datasets but the problem is that the histograms on the margins tend to be way too big, eclipsing the actual data. An example:enter image description here


In these plots it's important to see the individual points so I would like to scale the histograms down, but I don't find any documentation on how to adjust the size of the marginal distribution plots separately.

How could I do this?


Solution:

Since your code has not been posted, I will answer assuming that you have enabled marginal in plotly.express. express has a fixed size for individual graphs, I assume, so you can check the graph configuration information (fig.layout) for each graph size (domain ) in the graph configuration information (fig.layout) and set a new value. The answer code is taken from the reference.


import plotly.express as px


df = px.data.iris()


fig = px.scatter(df,

                 x="sepal_length",

                 y="sepal_width",

                 marginal_x="histogram",

                 marginal_y="rug")


# x1=0.8358,x2=0.8408

x1_, x2_ = 0.9, 0.905

# y1=0.7326, y2=0.7426

y1_, y2_ = 0.8, 0.81

fig.layout.xaxis.domain = (0.0, x1_)

fig.layout.xaxis2.domain = (x2_, 1.0)

fig.layout.xaxis3.domain = (0.0, x1_)

fig.layout.xaxis4.domain = (x2_, 1.0)

fig.layout.yaxis.domain = (0.0, y1_)

fig.layout.yaxis2.domain = (0.0, y1_)

fig.layout.yaxis3.domain = (y2_, 1.0)

fig.layout.yaxis4.domain = (y2_, 1.0)


fig.show()



Graph before customization 


Suggested blogs:

>How to create a One Page App with Angular.js, Node.js and MongoDB?

>How to Create an array based on two other arrays in Php

>How To Create Nested Table Structure In Angular?

>How to Create_function deprecated in PHP?

>How to delete duplicate names from Array in Typescript?

>How to do PHP Decryption from Node.js Encryption

>How to Set up the Android Emulator

>How to Set up the local environment for Angular development?


Ritu Singh

Ritu Singh

Submit
0 Answers