Your streamlit charts are cool but I prefer Matplotlib. Does Streamlit allow charting from other libraries?
Hey BisbeeBC,
I’m glad you like our native chart commands . We actually spent some time trying to find the right combination of “useful” and “it just works”, but definitely erred on the side of “it just works” as opposed to supporting a ton of features. Thankfully, you can use several different charting libraries with Streamlit, including Altair, Bokeh, Plotly, and — yes — also Matplotlib!
Using Matplotlib with Streamlit is easy: just write st.pyplot()
at the end of your code. For example:
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
arr = np.random.normal(1, 1, size=100)
plt.hist(arr, bins=20)
st.pyplot()
As a bonus, if you want to make your Matplotlib plot interactive, you can pass the pyplot figure object to Plotly:
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
arr = np.random.normal(1, 1, size=100)
fig = plt.figure()
plt.hist(arr, bins=20)
st.plotly_chart(fig)
Any plans to add HighCharts?
Not at the moment, but everything is open source, so you’re welcome to contribute it!
Can I ask what you like about HighCharts as opposed to other charting libraries?
Also, I’m going to change this thread name to reflect the different library questions being asked.
It’s what our product team prefers for presentations, so they ask us to use that.
Gotcha. It’s a really beautiful charting language and we’ve looked into some of the more 3D stuff they do. I’m personally a big fan of Altair and use that for most of my work. I know Plotly has some good 3D charts if you’re interested in that, but I also know that you have to use what the team wants to use!
FYI: I just created an issue for this and added it to our task board
I don’t know when we’ll be able to get to it, but if enough people star this on Github we could bump it up the priority list.
Thanks for reporting this!
Thank you so much for having these popular charting libraries supported on Streamlit. Probably another good reason to add HighCharts support is for more interactive map functions! HighCharts has the last piece of the puzzles when developing a BI dashboard with actions on map. (check out [here]!(https://www.highcharts.com/maps/demo/marker-clusters)
pyechart is easy-to-use, highly interactive and highly performant javascript visualization library under Apache license. Do you have the plan to add this library. This library has already got enough star.
This is good but I can’t get latex x,y labels to render in the plotly figure - works in the flat Matplotlib plot. Any ideas?
Guys this streamlit is really very helpfull, thank you so much.
I tried st.plotly_chart(fig) to convert my pyplot figure to plotly but got the following error:
AttributeError: 'XAxis' object has no attribute '_gridOnMajor'
Do you know how to fix it? Search on Stackoverflow and they mentioned it was a bug but I couldn’t find a solution.
Hey @cadasa
I believe Plotly no longer supports Matplotlib figures. See this old bug report I filed with them a while back:
In particular, this comment:
our matplotlib conversion utility should be considered deprecated at this point as it isn’t being actively maintained
Thanks for your reply! Is it possible to create interactive Matplotlib figure in Streamlit such as pan and zoom at least? Is plt.ion()
supported in Streamlit?
I get the following error using this code. I think after many years, it is not working now, so for future references, don’t use this method.
AttributeError: ‘Spine’ object has no attribute ‘is_frame_like’
Traceback:
File “c:\programdata\anaconda3\lib\site-packages\streamlit\script_runner.py”, line 332, in _run_script
exec(code, module.dict)
File “C:\Users\bdemir\OneDrive - Tekfen Holding A.Ş\Python\BD_Tunnel_Def\deneme.py”, line 13, in
st.plotly_chart(fig)
File “c:\programdata\anaconda3\lib\site-packages\streamlit\elements\plotly_chart.py”, line 116, in plotly_chart
marshall(
File “c:\programdata\anaconda3\lib\site-packages\streamlit\elements\plotly_chart.py”, line 139, in marshall
figure = plotly.tools.mpl_to_plotly(figure_or_data)
File “c:\programdata\anaconda3\lib\site-packages\plotly\tools.py”, line 112, in mpl_to_plotly
matplotlylib.Exporter(renderer).run(fig)
File “c:\programdata\anaconda3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py”, line 51, in run
self.crawl_fig(fig)
File “c:\programdata\anaconda3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py”, line 118, in crawl_fig
self.crawl_ax(ax)
File “c:\programdata\anaconda3\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py”, line 122, in crawl_ax
with self.renderer.draw_axes(ax=ax,
File “c:\programdata\anaconda3\lib\contextlib.py”, line 113, in enter
return next(self.gen)
File “c:\programdata\anaconda3\lib\site-packages\plotly\matplotlylib\mplexporter\renderers\base.py”, line 57, in draw_axes
self.open_axes(ax=ax, props=props)
File “c:\programdata\anaconda3\lib\site-packages\plotly\matplotlylib\renderer.py”, line 169, in open_axes
bottom_spine = mpltools.get_spine_visible(ax, “bottom”)
File “c:\programdata\anaconda3\lib\site-packages\plotly\matplotlylib\mpltools.py”, line 368, in get_spine_visible
spine_frame_like = spine.is_frame_like()