Black Lives Matter. Please consider donating to Black Girls Code today.

Rug plot without Plotly Express?

I want to plot a histogram and rug plot with graph_objects. for rug plots i only see docs and tuts with plotly express.

Are rugs possible with the graph_objects Figure interface? if so how do i implement them?

I basically want to make something like this (docs example of px.histogram with rug above) but with a graph_objects Figure.

My reasons for avoiding express is i’m not using dataframes, and i don’t want to introduce complexity (dependencies, processing time) for plotting my data.

Hi @grisaitis welcome to the forum! First of all, did you know that you can use plotly express without dataframes? For example

import numpy as np
x = np.random.randn(100)
fig = px.histogram(x=x, marginal='rug')

You can also build this kind of plot more manually with graph_objects of course. Doing a print(fig) on the px-generated figure will show you how. Here is an example

import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np

x = np.random.randn(200)
fig = make_subplots(rows=2, cols=1, row_heights=[0.3, 0.7], shared_xaxes=True)
), row=1, col=1)
fig.add_trace(go.Histogram(x=x), row=2, col=1)

Finally, there is a figure factory for distplots.

1 Like

thank you! your reply was incredibly informative.

1 Like