[PYTHON] (Memorandum) Make a 3D scatter plot with matplodlib

I wanted to make an image of a 3D scatter plot, so I made an image file using matplotlib with google colaboratory.

Label all points.

#Make Japanese available on matplotlib
!pip install japanize-matplotlib

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot
from numpy.random import rand
from pylab import figure
from google.colab import files
import pandas as pd
import japanize_matplotlib

#Label name and 3D coordinates of each point in the scatter plot
#If there are many points, it may be better to read csv
df = pd.DataFrame({'Lard theory': [20, 30, 20],
                   'Chicken oil theory': [10, 15, 15],
                   'Flavor oil theory': [5, -10, 10],
                   'Waper theory': [40, 50, 25],
                   'Ajinomoto': [15, -30, -15],
                   'Wok theory': [0, 0, 50],
                   'Aori theory of hot pot': [0, 5, 30],
                   'Hard rice theory': [-20, 20, 40],
                   'Thai rice theory': [-15, -25, 45],
                   'Egg over rice theory': [-35, -15, 45],
                   'Liquor theory': [10, -20, -30],
                   'Mayonnaise theory':[-5, 20, -10],
                   'Char siu theory': [40, 10, -15],
                   'Mizushima style fried rice theory':[10, -50, -50]
                   })

#Image size and resolution
fig = figure(figsize=(10, 10), dpi=100)
ax = fig.add_subplot(111, projection='3d')

#Draw each point
for i in range(df.shape[1]):
 ax.scatter(df.iloc[0,i],df.iloc[1,i],df.iloc[2,i])
 ax.text(df.iloc[0,i],df.iloc[1,i],df.iloc[2,i],  '%s' % (df.columns[i]), size=15)

#Axis label
ax.set_xlabel('delicious-subtle')
ax.set_ylabel('Ingredient taste-Seasoning taste')
ax.set_zlabel('Moist-Parapara')

#Shaft length
ax.set_xlim(-55, 55)
ax.set_ylim(-55, 55)
ax.set_zlim(-55, 55)

#Output png file name
pyplot.savefig( 'Fried rice tips-3D-Scatter plot.png' )
pyplot.show()
#DL of png file
files.download('Fried rice tips-3D-Scatter plot.png')

炒飯のコツ-3D-散布図.png

Recommended Posts

(Memorandum) Make a 3D scatter plot with matplodlib
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
A memorandum to make WebDAV only with nginx
3D plot with matplotlib
Create 3D scatter plot with SciPy + matplotlib (Python)
[Python] How to draw a scatter plot with Matplotlib
Make a fortune with Python
Make a fire with kdeplot
Make a 2D RPG with Ren'Py (3) -Items and Tool Shop
Let's make a GUI with python.
Make a sound with Jupyter notebook
Solve ABC166 A ~ D with Python
Let's make a breakout with wxPython
Make a recommender system with python
Make a filter with a django template
Let's make a graph with python! !!
Make a model iterator with PySide
Continuously color with matplotlib scatter plot
Make a nice graph with plotly
Try to make a web service-like guy with 3D markup language
Let's make a shiritori game with Python
Make a rare gacha simulator with Flask
Make a Notebook Pipeline with Kedro + Papermill
I came up with a way to make a 3D model from a photo.
Make a partially zoomed figure with matplotlib
Make a drawing quiz with kivy + PyTorch
Let's make a voice slowly with Python
Let's make a simple language with PLY 1
Make a logic circuit with a perceptron (multilayer perceptron)
Solve AtCoder ABC168 with python (A ~ D)
Make a Yes No Popup with Kivy
Make a wash-drying timer with a Raspberry Pi
Make a GIF animation with folder monitoring
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Make a desktop app with Python with Electron
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Draw a line / scatter plot on the CSV file (2 columns) with python matplotlib
Draw a flat surface with a matplotlib 3d graph
[Python] Make a game with Pyxel-Use an editor-
Make a monitoring device with an infrared sensor
Make a simple pixel art generator with Flask
Investment quest: Make a system trade with pyhton (1)
How to make a dictionary with a hierarchical structure.
I want to make a game with Python
Try to make a "cryptanalysis" cipher with Python
Solve A ~ D of yuki coder 247 with python
[Python] Make a simple maze game with Pyxel
Let's replace UWSC with Python (5) Let's make a Robot
Make a joyplot-like plot of R in python
Try to make a dihedral group with Python
[Chat De Tornado] Make a chat using WebSocket with Tornado
Make holiday data into a data frame with pandas
Make a LINE WORKS bot with Amazon Lex
I came up with a way to make a 3D model from a photo. 0 Projection to 3D space
How to make a 3D geometric figure with one click [From triangular pyramid to fractal]
A story about making 3D space recognition with Python
Make a morphological analysis bot loosely with LINE + Flask
Try to make a command standby tool with python
[Practice] Make a Watson app with Python! # 2 [Translation function]