Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting a 3D scatter plot using Python only returns an empty space (Jupyter Notebook)

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

like image 230
Pythoner Avatar asked Sep 03 '26 18:09

Pythoner


1 Answers

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

like image 157
Sheldore Avatar answered Sep 06 '26 09:09

Sheldore