[英]Matplotlib and Google Colab: Using ipympl
Whenever I try to plot a figure in a Google Colab notebook using matplotlib, a plot is displayed whenever I use %matplotlib inline
but is not displayed when I do %matplotlib ipympl
or %matplotlib widget
.每当我尝试 plot 使用 matplotlib 的 Google Colab 笔记本中的图形时,每当我使用%matplotlib inline
impl %matplotlib widget
时都会显示%matplotlib ipympl
小部件或不显示% How can I resolve this issue.我该如何解决这个问题。 My goal is to get the plot to be interactive.我的目标是让 plot 具有交互性。
Clarification: when I run
%matplotlib --list
I get the following output澄清:当我运行%matplotlib --list
我得到以下 output
Available matplotlib backends: ['tk', 'gtk', 'gtk3', 'wx', 'qt4', 'qt5', 'qt', 'osx', 'nbagg', 'notebook', 'agg', 'inline', 'ipympl', 'widget']
Thanks for your help!谢谢你的帮助!
Facing the same issue, I could not get ipympl
to work with Colab.面对同样的问题,我无法让ipympl
与 Colab 一起工作。 However, since you mentioned that " My goal is to get the plot to be interactive ", the next best solution is to use Plotly.但是,既然您提到“我的目标是让 plot 具有交互性”,那么下一个最佳解决方案是使用 Plotly。
Please see this shared Colab notebook for a minimum example.请参阅此共享的 Colab 笔记本以获取最小示例。
Python code also copied below for quick reference: Python 代码也在下面复制以供快速参考:
!pip install plotly
import plotly.express as px
SHEET_ID = '153pKW5IZRHwx9mLu_uU-hDSK0D3R19vR71EcgMYHn3I'
df = pd.read_csv('https://docs.google.com/spreadsheets/d/' + SHEET_ID + '/export?format=csv')
fig = px.scatter(data_frame=df, x="x", y="y", width=1000, height=800)
fig.show()
Available matplotlib backends: ['tk', 'gtk', 'gtk3', 'wx', 'qt4', 'qt5', 'qt', 'osx', 'nbagg', 'notebook', 'agg', 'inline', 'ipympl', 'widget']可用的 matplotlib 后端:['tk','gtk','gtk3','wx','qt4','qt5','qt','osx','nbagg','notebook','agg','内联','ipympl','小部件']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.