Colormap appears darker on another plot, how to change that ?
11 次查看(过去 30 天)
显示 更早的评论
I am plotting states of a solution at different times, and to visualise the solution I added a colormap that depends on the x position. I also superposed a sphere to help visualise the 3D plot. I should note that in order to color the plots, I used the patch function. Unfortunately, the 3D plot appears much darker than the energy plot (see the figures). I put two figures to show that the colormap still had some influence on the 3D plot the parameters for the plot of the sphere are :
'FaceColor' = [0.99, 0.99, 0.99];
alpha 0.07;
The two figures (at no point I can see colors as bright as at x=0 on the 3D-plot) :
Thank you for your time !
0 个评论
采纳的回答
LO
2021-6-13
编辑:LO
2021-6-13
you could change the colormap of your plot/s by adding (or subtracting) fixed values according to your needs
k = 0.01; % factor by which you want to increase color value
cmap = colormap; % actual colormap
size_cm=size(cmap); % get the size of the map
new_map = cmap + repelem(k,size_cm(1),size_cm(2)); % calculate the new colormap
new_map(new_map>1)=1; % make sure values do not exceed the max of 1
colormap(<subplot_handle>,new_map) % apply new map
here is my test code
clc
k = 0.02; % darker color, if you put 0 you have the default, negative values will darken the map
cmap = colormap;
size_cm=size(cmap);
new_map = cmap + repelem(k,size_cm(1),size_cm(2))
new_map(new_map>1)=1; % this makes sure there is no value higher than 1
new_map(new_map<0)=0; % this makes sure there is no value lower than 0
ax1=subplot(2,1,1)
surf(randi(50,50),'edgecolor','none')
colormap(ax1,new_map)
view(2)
ylim([0 50])
axis tight equal
k = 0.7; % brighter color, if you put 1 you have the max
cmap = colormap;
size_cm=size(cmap);
new_map = cmap + repelem(k,size_cm(1),size_cm(2))
new_map(new_map>1)=1; % this makes sure there is no value higher than 1
new_map(new_map<0)=0; % this makes sure there is no value lower than 0
ax2=subplot(2,1,2)
surf(randi(50,50),'edgecolor','none')
colormap(ax2,new_map)
view(2)
ylim([0 50])
axis tight equal
2 个评论
LO
2021-6-17
编辑:LO
2021-6-17
sadly that needs to be set manually for each plot but using some work around (if you just used the command colorbar this will change all colorbars in your figure). I do not remember it but somewhere in the MATLAB forum I am sure you'll find it. Maybe see here.
What worked for me sometimes was this (example using scatter plots of different colors):
color2 = flipud(cool(length( array_data1 ) ) );
color1 = hot(length( array_data2 ) );
hold on
scatter(array_data1(:,1),array_data1(:,2),1,'filled','CData', color1)
scatter(array_data2(:,1),array_data2(:,2),1,'filled','CData', color2)
In this example I am using part of 2 colormaps (hot and cool) based on the length of the data arrays to be plotted. One color vector is flipped as I wanted to have the first datapoints to be darker in both cases. The last data points of my 2 arrays are lighter in color. I guess this could work for any plot accepting CData property.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!