3

I am trying to create a 3D scatter plot using matplotlib in a Jupyter Notebook page. The code is not returning any errors, but I have yet to have the plot actually show up. The output is just blank.

Python: 3.7.3 Matplotlib: 3.0.3

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

%matplotlib inline
%matplotlib notebook

threedee = plt.figure().gca(projection='3d')
threedee.scatter(existing_df_2d.PC1, existing_df_2d.PC2, 
existing_df_2d.data_mean)

plt.show()

I included an example of the output (it's blank):

Output

2 Answers 2

2

You are using two backends

%matplotlib inline 
%matplotlib notebook

As a result, there seems to be a conflict between the two backends when invoked in parallel one after the other.

P.S: When I tried putting %matplotlib notebook in the same cell as the rest of the code, I did not see any figure. When I put it in a different cell, I see the figure.

Solution: Just use either the %matplotlib inline or %matplotlib notebook in a new separate cell and things will work fine

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

2 Comments

It worked! Thank you! Just out of curiosity, what is the difference between them? When should one be used over the other?
@alkhalifas : %matplotlib notebook allows you interactive functionalities such as rotating 3d figure, zooming in figures, within the notebook. By the way, I just realised that there is similar question asked here
-1

In my experience, %matplotlib notebook doesn't work with 3D plots unfortunately. Just use %matplotlib inline and you should be OK.

Comments

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.