I have two original plots, #1: original data
And #2: Fitted data
I would like the colors in the two plots to correspond. Meaning, the flat zero-value regions outside of the peaks are the same color, and other values (i.e., where f(x,y)=0.5, it’s the same color in both plots).
Here is some of my code:
# set up data
asdi_cb_merged = signalMatrix_FPI.ravel()
asdi_cb_merged_positive = np.abs(asdi_cb_merged)
valmin, valmax = np.min(asdi_cb_merged), np.max(asdi_cb_merged)
# define plotting sequence
def plot_data(x, y, data, title): #valmin, valmax,
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
surface = ax.plot_surface(x, y, data.reshape(data_points, data_points), cmap=cm.viridis) #, vmin=valmin, vmax=valmax
fig.colorbar(surface, shrink=0.5, aspect=20, cmap=cm.viridis, pad=0.07)
ax.view_init(elev=10, azim=30)
plt.show()
return
# Plot the original data
plot_data(x, y, asdi_cb_merged, 'Data, after complete reduction and CBM') #, valmin, valmax
# Do the (curve) fitting:
x_max = np.where(asdi_cb_merged.reshape(data_points,data_points)==np.max(asdi_cb_merged.reshape(data_points,data_points)))[1][0]
y_max = np.where(asdi_cb_merged.reshape(data_points,data_points)==np.max(asdi_cb_merged.reshape(data_points,data_points)))[0][0]
iGuess = (11, x_max, y_max, 10, 0, 1) # Amp, xy, yx, sigma, theta, offset
lower_upper_bounds = ((0, 0, 0, 1, -np.inf, -np.inf), (np.inf, 200, 200, 45, np.inf, np.inf))
popt, pcov = curve_fit(twoD_Gaussian, (x, y), asdi_cb_merged, p0=iGuess, bounds=lower_upper_bounds)
data_fitted = twoD_Gaussian((x, y), *popt)
# Plot the fitted data
plot_data(x, y, data_fitted, 'Fitted Data') #, valmin, valmax
I thought by putting in the valmin and valmax variables for the first plot, I would get equal colors for equal values Ithe second; instead, I got one color in both plots for all values. Like this:
Monochromatic color values #1
And
Monochromatic color values #2
Do you know how I can fix this?
I tried putting the commented out valmin & valmax terms into the code above. The 2nd set of images resulted.