-
-
Save luisdamed/68b714d312633b18507ca6cefc0a3bff to your computer and use it in GitHub Desktop.
A simple script to visualize data from Marlin's G29 mesh leveling command. It provides interactive plotting via Plotly
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 libraries needed | |
import plotly.graph_objects as go | |
import pandas as pd | |
from datetime import datetime | |
import os | |
import tkinter as tk | |
from tkinter import filedialog | |
# %% Ask the user to select the file containing the mesh bed level data | |
box_open = tk.Tk() | |
box_open.withdraw() | |
# Build a list of tuples for each file type the file dialog should display | |
my_filetypes = [('all files', '.*'), ('text files', '.txt'), ('Comma-separated files', '.csv')] | |
# Ask the user to select a single file name. | |
data_file = filedialog.askopenfilename(parent=box_open, | |
initialdir=os.getcwd(), | |
title="Please select the file containing the mesh bed level data", | |
filetypes=my_filetypes) | |
# %% Read data from a csv | |
z_data = pd.read_table(data_file, delimiter= " ", skiprows = 0, skipinitialspace= "true" ) | |
# Get current time | |
now = datetime.now() | |
current_time = now.strftime("%d/%b/%y %H:%M:%S") | |
title_string = f'G29 Mesh data - {current_time}' | |
# Create surface figure | |
fig = go.Figure(data=[go.Surface(z=z_data.values)]) | |
#%% Formatting | |
fig.update_layout(title= title_string, title_y = .9, autosize=False, | |
width=700, height=450, | |
margin=dict(l=50, r=10, b=10, t=20)) | |
# Use per-axis property definition | |
fig.update_scenes(xaxis_range = [0, len(z_data.columns.values) ], | |
yaxis_range = [0, len(z_data.index.values) ], | |
zaxis_range=[-1, 1] ) | |
# Or pack the properties in dict format (more compact and clean) | |
fig.update_scenes( aspectratio = {'x': .7, 'y': .7, 'z' : 0.5}, | |
camera_eye = {'x': 0, 'y': -1, 'z' : 0.9}, | |
camera_projection_type='perspective') | |
fig.update_traces(colorscale = 'Portland') #RdBu | |
fig.update_layout(plot_bgcolor='white') | |
fig.update_coloraxes(colorbar_lenmode='pixels', colorbar_len= 200) | |
# Export to html | |
box_save = tk.Tk() | |
box_save.withdraw() | |
# Build a list of tuples for each file type the file dialog should display | |
my_filetypes = [('all files', '.*'), ('text files', '.txt'), ('Comma-separated files', '.csv')] | |
# Ask the user to select a single file name. | |
save_name = filedialog.asksaveasfilename(parent=box_save, | |
initialdir=os.getcwd(), | |
title="Please type the name for the new file", | |
filetypes=my_filetypes) | |
fig.show() | |
fig.write_html(save_name) | |
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
0 1 2 3 4 5 6 7 | |
0 +0.300 +0.145 +0.030 -0.020 -0.040 -0.240 -0.375 -0.465 | |
1 +0.255 +0.085 -0.060 -0.100 -0.130 -0.320 -0.495 -0.570 | |
2 +0.070 -0.070 -0.175 -0.185 -0.185 -0.370 -0.520 -0.605 | |
3 +0.175 +0.050 -0.020 -0.005 +0.025 -0.160 -0.300 -0.350 | |
4 +0.455 +0.285 +0.135 +0.115 +0.115 -0.070 -0.255 -0.375 | |
5 +0.425 +0.205 +0.100 +0.090 +0.060 -0.145 -0.320 -0.405 | |
6 +0.400 +0.250 +0.120 +0.125 +0.125 -0.045 -0.180 -0.275 | |
7 +0.395 +0.220 +0.150 +0.180 +0.190 +0.045 -0.075 -0.105 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment