✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

How to set x_Axis range while plotting multiple traces plotly python

I’m actually trying to plot multiple traces with one x_axis .

the code I used for the plots are :

import plotly.graph_objects  as go
import numpy
x1= numpy.array([datetime.time(4, 45), datetime.time(5, 15), datetime.time(5, 30),datetime.time(5, 45), datetime.time(6, 0), datetime.time(6, 15),
       datetime.time(6, 30), datetime.time(6, 45), datetime.time(7, 0),datetime.time(7, 15), datetime.time(7, 30), datetime.time(7, 45),
       datetime.time(8, 0), datetime.time(8, 15), datetime.time(8, 30),datetime.time(8, 45), datetime.time(9, 0), datetime.time(9, 15),
       datetime.time(9, 30), datetime.time(9, 45), datetime.time(10, 0),datetime.time(10, 15), datetime.time(10, 30),datetime.time(10, 45), datetime.time(11, 0), datetime.time(11, 15),datetime.time(11, 30), datetime.time(11, 45), datetime.time(12, 0),
       datetime.time(12, 15), datetime.time(12, 30),datetime.time(12, 45), datetime.time(13, 0), datetime.time(13, 15),datetime.time(13, 30), datetime.time(13, 45), datetime.time(14, 0),datetime.time(14, 15), datetime.time(14, 30),datetime.time(14, 45), datetime.time(15, 0), datetime.time(15, 15),datetime.time(15, 30), datetime.time(15, 45), datetime.time(16, 0),datetime.time(16, 15), datetime.time(16, 30),
       datetime.time(16, 45), datetime.time(17, 0), datetime.time(17, 15),datetime.time(17, 30), datetime.time(17, 45), datetime.time(18, 0),
       datetime.time(18, 15), datetime.time(18, 30),datetime.time(18, 45), datetime.time(19, 0), datetime.time(19, 15),datetime.time(19, 30), datetime.time(19, 45), datetime.time(20, 0),datetime.time(20, 15), datetime.time(20, 30),
       datetime.time(20, 45), datetime.time(21, 0), datetime.time(21, 15),datetime.time(22, 15), datetime.time(22, 45),datetime.time(23, 15), datetime.time(23, 30),datetime.time(23, 45)], dtype=object)

y1= numpy.array([ 13.,  16.,   8.,  28.,  45.,  61.,  74., 133., 191., 177., 249.,219., 249., 197.,  89.,  94.,  38.,  16.,   4.,   4.,  12.,  24.,
        15.,  34.,  19.,  23.,  93.,  30.,  40.,  30.,  54.,  41.,  27.,23.,  13.,  31.,  15.,  19.,  18.,  14.,  32.,  19.,  14.,  23.,102.,  30.,  17.,  18., 105.,  67.,  55.,  56., 106.,  50.,  25.,17.,  12.,   8.,  17.,  12.,  15.,   8.,   7.,   6.,   1.,  10.,9.,   5.,   1.,   1.,   1.])


x2 = numpy.array(
    [datetime.time(0, 15), datetime.time(4, 45), datetime.time(5, 15),datetime.time(5, 30), datetime.time(5, 45), datetime.time(6, 0),datetime.time(6, 15), datetime.time(6, 30), datetime.time(6, 45),datetime.time(7, 0), datetime.time(7, 15), datetime.time(7, 30),
       datetime.time(7, 45), datetime.time(8, 0), datetime.time(8, 15),datetime.time(8, 30), datetime.time(8, 45), datetime.time(9, 0),datetime.time(9, 15), datetime.time(9, 30), datetime.time(9, 45),datetime.time(10, 0), datetime.time(10, 15), datetime.time(10, 30),datetime.time(10, 45), datetime.time(11, 0), datetime.time(11, 15),
       datetime.time(11, 30), datetime.time(11, 45), datetime.time(12, 0),datetime.time(12, 15), datetime.time(12, 30),datetime.time(12, 45), datetime.time(13, 0), datetime.time(13, 15),datetime.time(13, 30), datetime.time(13, 45), datetime.time(14, 0),datetime.time(14, 15), datetime.time(14, 30),
       datetime.time(14, 45), datetime.time(15, 0), datetime.time(15, 15),datetime.time(15, 30), datetime.time(15, 45), datetime.time(16, 0),datetime.time(16, 15), datetime.time(16, 30),datetime.time(16, 45), datetime.time(17, 0), datetime.time(17, 15),
       datetime.time(17, 30), datetime.time(17, 45), datetime.time(18, 0),datetime.time(18, 15), datetime.time(18, 30),datetime.time(18, 45), datetime.time(19, 0), datetime.time(19, 15),datetime.time(19, 30), datetime.time(19, 45), datetime.time(20, 0),datetime.time(20, 15), datetime.time(20, 30),datetime.time(20, 45), datetime.time(21, 0), datetime.time(21, 15),
        datetime.time(21, 30), datetime.time(21, 45), datetime.time(22, 0),datetime.time(22, 15), datetime.time(22, 30),datetime.time(22, 45), datetime.time(23, 0), datetime.time(23, 15),datetime.time(23, 30)], dtype=object)

y2 = numpy.array([  1.,  16.,  15.,   7.,  27.,  27.,  86.,  39.,  92., 157., 257.,
       278., 253., 273., 217., 200.,  94.,  86.,  54.,  42.,  24.,  37.,34.,  38.,  34.,  35.,  26.,  51.,  29.,  35.,  30.,  62.,  27.,30.,  19.,  19.,  24.,  23.,  19.,  16.,  13.,  33.,  36.,  20.,
        35., 127.,  50.,  22.,  28., 103.,  84.,  43.,  41., 100.,  33.,33.,  21.,  20.,  19.,  20.,  13.,   8.,  12.,   8.,  11.,   2.,
        14.,   3.,   4.,   4.,   7.,   1.,   3.,   1.,   2.,   1.])

fig = go.Figure(data=[
    go.Scatter(
        x= x1,
        y= y1,
        mode = 'markers'
            ),
go.Scatter(
        x= x2,
        y= y2,
    mode = 'markers'
    )])
fig.show()

The given result is Here:

As you can see from figure the result gives a strange behavior and my both traces are starting from datetime.time(4, 45) which is not the case. Noting that my x_Axis range is varying , which I think is the main problem, and in fact I have multiple sample data like that where x_axis is a datetime.time, where each sample data (Xn,Yn) has it’s own interval and it’s own length of values but I know that my x_axis values are varying from an interval of datetime.time(0,0) as a minimum value to a datetime.time(23,45) as maximum value with a step of 15min.

So each of my x1 , x2 …,xn is taking values in this interval , so I would like to fix the x_axis with this global interval( which I referred to range_data in the next code) and then plot any of my sample data on it.

range_data = pd.DataFrame()
range_data['range_data'] = pd.date_range("00:00", "23:45", freq="15min").time
range_data = range_data.set_index('range_data')