首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >VSCODE: jupyter添加交互式matplotlib绘图%matplotlib小部件不交互工作

VSCODE: jupyter添加交互式matplotlib绘图%matplotlib小部件不交互工作
EN

Stack Overflow用户
提问于 2022-03-10 09:22:11
回答 1查看 2.2K关注 0票数 6

下面的示例不适用于VSCODE。它可以工作(不过,它可以在网页浏览器中的木星笔记本中使用%matplotlib笔记本)。

代码语言:javascript
运行
复制
# creating 3d plot using matplotlib 
# in python
  
# for creating a responsive plot
# use %matplotlib widget in VSCODE
#%matplotlib widget
%matplotlib notebook
  
# importing required libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
  
# creating random dataset
xs = [14, 24, 43, 47, 54, 66, 74, 89, 12,
      44, 1, 2, 3, 4, 5, 9, 8, 7, 6, 5]
  
ys = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 3,
      5, 2, 4, 1, 8, 7, 0, 5]
  
zs = [9, 6, 3, 5, 2, 4, 1, 8, 7, 0, 1, 2, 
      3, 4, 5, 6, 7, 8, 9, 0]
  
# creating figure
fig = plt.figure()
ax = Axes3D(fig)
  
# creating the plot
plot_geeks = ax.scatter(xs, ys, zs, color='green')
  
# setting title and labels
ax.set_title("3D plot")
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
ax.set_zlabel('z-axis')
  
# displaying the plot
plt.show()

其结果应该是您得到一个可以使用鼠标箭头交互旋转的绘图。

在VSCODE中,您可以单击,并提供一个呈现器。选中的是JupyterIPWidget渲染者。其他渲染器显示情节,但不允许交互操作。

还出现了一项警告:

代码语言:javascript
运行
复制
/var/folders/kc/5p61t70n0llbn05934gj4r_w0000gn/T/ipykernel_22590/1606073246.py:23:
 MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure is 
deprecated since 3.4. Pass the keyword argument auto_add_to_figure=False 
and use fig.add_axes(ax) to suppress this warning. The default value of 
auto_add_to_figure will change to False in mpl3.5 and True values will
 no longer work in 3.6.  This is consistent with other Axes classes.
  ax = Axes3D(fig)
EN

回答 1

Stack Overflow用户

发布于 2022-11-25 18:53:23

这种行为是预期的-- VS代码中不支持%matplotlib notebook。您应该使用%matplotlib widget代替。请参阅https://github.com/microsoft/vscode-jupyter/wiki/Using-%25matplotlib-widget-instead-of-%25matplotlib-notebook,tk,etc

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71421655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档