Several different labels and sublabels for axis

is this possible to achieve this with streamlit?
I have date and time as two separate columns of a pandas dataframe. I want to use both of them as values on the X axis as shown on the sketch.

Not with streamlit per se but with a visualization library like matplotlib.pyplot. Here is an attempt to the sketch:

import streamlit as st
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
import numpy as np

## Create a dummy dataframe that uses times
dataframe = pd.DataFrame({'Time':pd.date_range("2018-11-01", "2018-11-04", freq="1H")})
dataframe['Value'] = np.random.random(len(dataframe))

## Create figure with matplotlib
fig,ax = plt.subplots(figsize=[8,5])
ax.set_title("My awesome plot")

## Modify the major x-axis to show only days
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %d %Y"))
ax.tick_params(axis='x', which='major', length=50, width=0.8)
for label in ax.get_xticklabels(which='major'):
    label.set(ha='left', va='top')

## Modify the minor x-axis to show only hours
for label in ax.get_xticklabels(which='minor'):
    label.set(rotation=90, ha='center', va='top',fontsize=8)

## Streamlit layout to display
st.header(":clock130: Plotting dates :clock130: ")
st.write("#### The pandas dataframe")

Useful links:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.