0

I'm trying to better understand 3D plotting using various tutorials online. I tried to recreate one of these online tutorials, this one in particular by running some of the code in my own Jupyter Notebook, however, when I try this I get a suspicious error.

I am running the first code block from the website (attached below) and I get this eror whenever I try and run it. This error is unclear to me so I am having trouble resolving it!

---------------------------------------------------------------------------
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's the code)

# 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()

I have made sure I downloaded the correct libraries and I checked to see what version of python I was running, 3.8.3.

1
  • just a suggestion but are you not using %matplolib inline in your notebook? I have a feeling that might be the issue but not completely sure Commented Nov 6, 2022 at 2:13

1 Answer 1

0

Use the magic functions %matplotlib inline

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.