Display "july" plots on streamlit?

I was trying to integrate calendar heatmaps, and july package (july Β· PyPI) looks exactly like what I need. However, how do I get to display the plot? Sorry if this is a silly question.

Steps to reproduce

Code snippet:

import numpy as np
import matplotlib.pyplot as plt
import july
from july.utils import date_range

dates = date_range("2020-01-01", "2020-12-31")
data = np.random.randint(0, 14, len(dates))
july.month_plot(dates, data, month=5, date_label=True, ax=axes[0])

```st.write doesn't seem to work.

Never mind, I figured:
p = july.month_plot(dates, data, month=5, date_label=True, ax=axes[0])
st.pyplot(p.figure)

still error

While st.pyplot expects a matplotlib Figure object, you pass the Axes to july where you want the heatmap plotted.


import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
import july
from july.utils import date_range

## Create data
dates = date_range("2020-01-01", "2020-12-31")
data = np.random.randint(0, 100, len(dates))

## Create a figure with a single axes
fig, ax = plt.subplots()

## Tell july to make a plot in a specific axes
july.month_plot(dates, data, month=2, date_label=True, ax=ax, colorbar=True)

st.title("πŸ“Š A `july.month_plot()` in streamlit")
## Tell streamlit to display the figure
st.pyplot(fig)

Here is a diagram of the different elements in a matplotlib Figure β†’ Anatomy of a figure β€” Matplotlib 3.6.2 documentation.

1 Like

Thank you, that’s exactly it!

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