Created
November 8, 2024 14:02
-
-
Save quanon/72594d2677645de1af33ab3f02242aa8 to your computer and use it in GitHub Desktop.
直径・幅・重さを 3D プロットする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import os | |
import plotly.express as px | |
import pandas as pd | |
diameters = [] | |
widths = [] | |
weights = [] | |
csv_filepath = os.path.join(os.environ['HOME'], 'Downloads/yoyos.csv') | |
data = [] | |
with open(csv_filepath, 'r', encoding='utf-8') as f: | |
reader = csv.reader(f) | |
for i, row in enumerate(reader): | |
if i == 0: | |
continue | |
name = row[0] | |
diameter = round(float(row[3]), 1) | |
width = round(float(row[4]), 1) | |
weight = round(float(row[5]), 1) | |
data.append((name, diameter, width, weight)) | |
df = pd.DataFrame(data, columns=['Name', 'Diameter', 'Width', 'Weight']) | |
labels = {'Diameter': 'diameter (mm)', 'Width': 'width (mm)', 'Weight': 'weight (g)'} | |
fig = px.scatter_3d(df, x='Diameter', y='Width', z='Weight', hover_name='Name', labels=labels) | |
fig.update_traces(marker=dict(size=5)) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment