How do I stop my colorbar from adjusting automatically to represent the saturation within my figure

30 views (last 30 days)
I have created a figure to represent how the saturation of a domain changes over 50 timesteps. I would like my colorbar NOT to adjust the shades automatically (depending on what saturation is for that timestep).
Whilst I have set the limits of the colorbar to [0 1] the color marking a saturation of 0.3 changes from timestep 1 (blue color) to time step 25 (yellow color), I would like to stop the colors of the colorbar from adjusting automatically each timestep (so to stick with the origional colorbar shown in timestep 1), so I can show how there is little of the yellow fluid left at the end of my timesteps in comparisonn to the beginning of my timesteps.
Here is my plotting code and figures for refererance, any help would be greatly appreciated! TIA
figure('Name', 'Well Positions');
format long;
plotToolbar(G, states1);
c = colorbar;
colormap parula
c.Limits = [0 1];
%clim([0, 1]);
plotWell(G, W, 'radius', 1, 'height', 5, 'color', 'k');
axis equal tight
xlabel ("Y (ft)")
ylabel ("X (ft)")
zlabel ("Z (ft)")
view(3);

Answers (1)

Mrutyunjaya Hiremath
Mrutyunjaya Hiremath on 17 Aug 2023
To prevent the color map from adjusting its scale dynamically over each timestep, you should set the CLim property of the current axis (gca) to the desired limits. In your case, this would be [0 1].
You can set this property right after your plotting commands and before you adjust the colorbar and other formatting settings.
Here's how you can modify your code:
figure('Name', 'Well Positions');
format long;
plotToolbar(G, states1);
colormap parula
caxis([0 1]); % Set color axis limits
c = colorbar;
c.Limits = [0 1];
plotWell(G, W, 'radius', 1, 'height', 5, 'color', 'k');
axis equal tight
xlabel ("Y (ft)")
ylabel ("X (ft)")
zlabel ("Z (ft)")
view(3);
The key addition here is the caxis([0 1]); line. This ensures that the color axis limits are set to the range [0, 1] for all timesteps, hence the colors will remain consistent across all timesteps.

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!