How can I add more text or columns to the y-axis in a plotly.express
timeline visualization?
to get something like this: is this possible?
sample code with only three drugs:
import plotly.express as px
import pandas as pd
sample= {'index': [0, 1, 2, 3, 4], 'columns': ['row_id', 'subject_id', 'hadm_id', 'icustay_id', 'startdate', 'enddate', 'drug_type', 'drug', 'drug_name_poe', 'drug_name_generic', 'formulary_drug_cd', 'gsn', 'ndc', 'prod_strength', 'dose_val_rx', 'dose_unit_rx', 'form_val_disp', 'form_unit_disp', 'route'], 'data': [[32600, 42458, 159647, 'nan', '2146-07-21 00:00:00', '2146-07-25 00:00:00', 'MAIN', 'Pneumococcal Vac Polyvalent', 'Pneumococcal Vac Polyvalent', 'PNEUMOcoccal Vac Polyvalent', 'PNEU25I', 48548.0, 6494300.0, '25mcg/0.5mL Vial', '0.5', 'mL', '1', 'VIAL', 'IM'], [32601, 42458, 159647, 'nan', '2146-07-21 00:00:00', '2146-08-22 00:00:00', 'MAIN', 'Bisacodyl', 'Bisacodyl', 'Bisacodyl', 'BISA5', 2947.0, 536338101.0, '5 mg Tab', '10', 'mg', '2', 'TAB', 'PO'], [32602, 42458, 159647, 'nan', '2146-07-21 00:00:00', '2146-07-22 00:00:00', 'MAIN', 'Bisacodyl', 'Bisacodyl', 'Bisacodyl (Rectal)', 'BISA10R', 2944.0, 574705050.0, '10mg Suppository', '10', 'mg', '1', 'SUPP', 'PR'], [32603, 42458, 159647, 'nan', '2146-07-21 00:00:00', '2146-07-22 00:00:00', 'MAIN', 'Senna', 'Senna', 'Senna', 'SENN187', 19964.0, 904516561.0, '1 Tablet', '1', 'TAB', '1', 'TAB', 'PO'], [32604, 42458, 159647, 'nan', '2146-07-21 00:00:00', '2146-07-21 00:00:00', 'MAIN', 'Docusate Sodium (Liquid)', 'Docusate Sodium (Liquid)', 'Docusate Sodium (Liquid)', 'DOCU100L', 3017.0, 121054410.0, '100mg UD Cup', '100', 'mg', '1', 'UDCUP', 'PO']]}
df = pd.DataFrame(index=sample['index'], columns=sample['columns'], data=sample['data'])
fig = px.timeline(df, x_start="startdate", x_end="enddate", y="drug")
fig.update_yaxes(autorange="reversed")
fig.show()
Thank you