I would like to create a 3D surface with the data I got in an analysis. I have 18 samples (t0, t1, ...) to which an absorbance signal is linked at each wavelength (from 300 to 800nm approximately).
My problem is that while entering the data through pandas I can't plot anything and I get an error ms:
shape mismatch: objects cannot be broadcast to a single shape
What am I supposed to do or where am I wrong?
(ps. I am attaching the image with data series to make the problem clearer)
** I ruled out the nan
problem in the last column by writing the array by hand so that's not the problem, but if you know how to remove the last n values from an array, I'd like to know too.
image:
Code:
import pandas as pd
import ipywidgets as widgets
f="3d-chart.xlsx"
data = pd.ExcelFile(f)
shet=widgets.Dropdown(
options=data.sheet_names,
description='Data sheet:',
disabled=False,
)
display(shet)
data=pd.read_excel(f,sheet_name=shet.value)
data #for show data database
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
import numpy as np
fig, ax = plt.subplots(subplot_kw={"projection": "3d"}, figsize=(15,15))
# Make data.
X = np.array(data[data.columns[0]])
#Y = np.array(data[data.columns[19]])
#X, Y = np.meshgrid(X, Y)
Z = np.array([(data[data.columns[i]])for i in range (1,18)])
# Plot the surface.
surf = ax.bar(X, Y, Z, cmap=cm.coolwarm,linewidth=3, antialiased=False)
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
and the error was:
ValueError: shape mismatch: objects cannot be broadcast to a single shape