Plotly express strip plot does not separate the points by color when temporal data is used on the x-axis.
Set up some data with random groups and status (which will be the color of points in our plot)
import pandas as pd
import plotly.express as px
import random
random.seed(0)
n = 100
df = pd.DataFrame(
data=dict(
group=random.choices(["A","B","C"], k=n),
status=random.choices(["on", "off"], k=n),
time=pd.date_range('2/5/2019', periods = n, freq ='2H'),
)
)
Our DataFrame is
print(df)
group status time
0 C off 2019-02-05 00:00:00
1 C off 2019-02-05 02:00:00
2 B on 2019-02-05 04:00:00
3 A off 2019-02-05 06:00:00
4 B on 2019-02-05 08:00:00
.. ... ... ...
95 C on 2019-02-12 22:00:00
96 C off 2019-02-13 00:00:00
97 A on 2019-02-13 02:00:00
98 B off 2019-02-13 04:00:00
99 B on 2019-02-13 06:00:00
[100 rows x 3 columns]
When we go to make a strip plot with "time"
as the x-axis, using status
as the color, all status values are on the same y-level
px.strip(df, x="time", y="group", color="status")
But if we were to use the DataFrame's integer indices as the x-axis, the colors are placed on different y levels
px.strip(df.reset_index(), x="index", y="group", color="status")
I would like the temporal data to plot like the integer data (with different colors on different y levels). I see nothing in the documentation that says temporal data is an issue.
px.strip seems to be an appropriation of the boxplot function.
fig=px.strip(...) ;print(fig.data)
. In this case, setting the jitter value to 0 eliminates the blurring of the scatter. The comment in the already existing answer says that the hover also needs time series data, so I will add the time to the custom data and update it. Also, thestatus
is updated throughout and only theon
graph is updated.