Hello,
I have a 4D visualization (with color as the 4th dimension) that was built using matplotlib3d. I have been asked to move this visualization to a web app and I would like to use Dash.
I am wondering if anyone has examples of code that integrates matplotlib in with their dash build or is the situation that you have to build your visualizations from the ground up with the dash syntax?
Here is an example of my code that I would like to “translate” into Dash syntax:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import animation
%matplotlib inline
#read in data. Break it up for generate of approach and retract visulaizations.
data = pd.read_csv('PHASEdata.csv',header=None, skiprows=1)
z = data[0]
z_approach = z[:500]
z_retract = z[500:]
#Reshape data into len(z) arrays of 48x48 pixels and index.
pslist = []
for k in range(len(z)):
phaseshift = data.iloc[k,1:]
ps = np.array(phaseshift)
ps_reshape = np.reshape(ps,(48,48))
pslist.append(ps_reshape)
#Create meshgrid unto which phase shift values can be mapped.
a = np.linspace(0, 47, 48)
b = np.linspace(0, 47, 48)
c = z_approach
x, z, y = np.meshgrid(a, c, b)
#Create list of phase intensities.
psasas = []
for k in range(len(c)):
C = pslist[k]
for i in range(len(a)):
B = pslist[k][i]
for j in range(len(b)):
A = pslist[k][i][j]
psasas.append(A)
l = psasas
#Generate plot
fig = plt.figure(figsize=(9,9))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z, c=l, alpha=0.4)
ax.set_xlabel('X(nm)', fontsize=15)
ax.set_ylabel('Y(nm)', fontsize=15)
ax.set_zlabel('Z(nm)', fontsize=15)
ax.set_title('3D Plot for the AFM Phase Shift of XXX', fontsize=20)
plt.show()
It seems that one of my issues is that the lists I generate are not one of the native data types that JSON, and by extension, Dash supports (aka objects, arrays, strings, numbers, booleans, and null). I am not sure how I can modify my code so it is html readable, but still am able to generate my plot. Is it even possible? If not, what would be my best bet going forward?
I am very new to programming, so any comments are helpful. Thank you in advance!