VSCode:Jupyter 添加交互式 Matplotlib 图表 %matplotlib widget 无法交互工作

7
以下示例在VSCODE中无法工作。但在Jupyter笔记本电脑中使用%matplotlib notebook命令在Web浏览器中可以运行。
# 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 Renderer。其他渲染器显示绘图,但不允许交互式操作。同时会出现一个警告:
/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)

你解决了吗? - honkskillet
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接