我尝试使用各种在线教程来更好地理解3D绘图。我试图通过运行我自己的Jupyter Notebook中的一些代码来重新创建这些在线教程中的一个this one in particular,然而,当我尝试这样做时,我得到了一个可疑的错误。
我正在运行网站上的第一个代码块(附在下面),每当我尝试运行它时,我都会遇到这个错误。这个错误对我来说不清楚,所以我很难解决它!
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-304-35f6bb1e64fb> in <module>
20
21 # creating figure
---> 22 fig = plt.figure()
23 ax = Axes3D(fig)
24
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/pyplot.py in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)
538 If there is an active figure, it will be updated and displayed before the
539 pause, and the GUI event loop (if any) will run during the pause.
--> 540
541 This can be used for crude animation. For more complex animation use
542 :mod:`matplotlib.animation`.
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in new_figure_manager(cls, num, *args, **kwargs)
3356
3357 Parameters
-> 3358 ----------
3359 tool : tool_like
3360 The tool to add, see `.ToolManager.get_tool`.
~/opt/anaconda3/lib/python3.8/site-packages/ipympl/backend_nbagg.py in new_figure_manager_given_figure(num, figure)
485 if 'nbagg.transparent' in rcParams and rcParams['nbagg.transparent']:
486 figure.patch.set_alpha(0)
--> 487 manager = FigureManager(canvas, num)
488
489 if is_interactive():
~/opt/anaconda3/lib/python3.8/site-packages/ipympl/backend_nbagg.py in __init__(self, canvas, num)
459 FigureManagerWebAgg.__init__(self, canvas, num)
460 self.web_sockets = [self.canvas]
--> 461 self.toolbar = Toolbar(self.canvas)
462
463 def show(self):
~/opt/anaconda3/lib/python3.8/site-packages/ipympl/backend_nbagg.py in __init__(self, canvas, *args, **kwargs)
120 def __init__(self, canvas, *args, **kwargs):
121 DOMWidget.__init__(self, *args, **kwargs)
--> 122 NavigationToolbar2WebAgg.__init__(self, canvas, *args, **kwargs)
123
124 self.on_msg(self.canvas._handle_message)
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_webagg_core.py in __init__(self, canvas)
395 self.message = ''
396 self._cursor = None # Remove with deprecation.
--> 397 super().__init__(canvas)
398
399 def set_message(self, message):
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in __init__(self, canvas)
2706 elif button_name in rcParams['keymap.forward']:
2707 toolbar.forward()
-> 2708
2709
2710 class NonGuiException(Exception):
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in _init_toolbar(self)
2769
2770 figure.canvas.mpl_disconnect(
-> 2771 figure.canvas.manager.button_press_handler_id)
2772 """
2773
NotImplementedError:
(Here的代码)
# creating 3d plot using matplotlib
# in python
# for creating a responsive plot
%matplotlib widget
# 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()
我已经确保我下载了正确的库,我检查了一下我运行的是什么版本的python,3.8.3。
1条答案
按热度按时间rta7y2nd1#
使用魔术函数%matplotlib内联