Hi Niraj,
To create a gradient color map based on a continuous variable like time in your scatter plot, you can manually map the colors of your points to a colormap instead of using "gscatter", which is more suited for categorical variables and doesn't automatically provide a gradient colormap. Here's how you can modify your code to achieve a gradient color scheme based on the "Final_max" variable:
- Map your time variable to a colormap: First, you need to map the values of your time variable (Final_max) to a colormap. MATLAB provides various colormaps (e.g., 'jet', 'hsv', 'hot', etc.), and you can choose one that suits your data visualization needs. Here is a list of available colormaps for MATLAB: https://www.mathworks.com/help/matlab/ref/colormap.html#buc3wsn-6:~:text=%7C%20%27default%27-,Colormap,-for%20the%20new
- Create a scatter plot and manually set the colors: Instead of using "gscatter", use the "scatter" function and manually set the colors of each point based on the mapped colormap values.
- Add a colorbar: Add a colorbar to your plot to represent the range of your time variable.
Here is how you can do it:
Final_max = Final_max(~isnan(Final_max));
slope = slope(~isnan(Final_max));
usarea = usarea(~isnan(Final_max));
Final_max_normalized = (Final_max - min(Final_max)) / (max(Final_max) - min(Final_max));
colors = colormap(colormapName);
numColors = size(colors, 1);
colorIndices = ceil(Final_max_normalized * (numColors - 1)) + 1;
pointColors = colors(colorIndices, :);
scatter(usarea, slope, [], pointColors, 'filled');
set(gca, 'xscale', 'log', 'yscale', 'log');
xlabel('Upstream Drainage Area (sq km)');
xline(7*10^5, 'Color', 'r', 'LineStyle', '--');
plot([1.1*10^6 10^10], [0.15 0.15], '--r');
plot([7*10^5 5*10^9], [0.2 10^-4], '--r');
caxis([min(Final_max) max(Final_max)]);
title('Color represents Final max');
Given below is the obtained plot:
Hope this helps!