Azzera filtri
Azzera filtri

How can I put a custom colorbar into a figure with multiple datasets/datatypes

11 visualizzazioni (ultimi 30 giorni)
I have an interesting situation where I am trying to overlay 3 different datatypes and make a custom colorbar for one of them.
For context, it first has and RBG image loaded using imagesc, scaled to lat/lon limits. The colors of the image are supposed to correlate with concentration and this is what I which to display in the color bar (the dark green to bright yellow).
Secondly, it has two contours (contourf): one for the depth contours and one for the coastline. This is overlayed so that it lines up with the RGB image. These contours also have their own colormap
Finally, it has 3 sets of data plotted using just 'plot' overtop of that.
I have created a custom color set corresponding to the range of colors in the RGB image, but I need the land and everything else to follow a different colormap. I also need to somehow scale the colorbar output to the corresponding concentrations. Currently, the colorbar only uses the depth data, and changing the colormap changes the colormap of all data sets. I hope the images below make the issue more clear.
I would like the colorbar to have the colors of the first picture, but scaled to the concentrations and not depth. And I would like the rest of the image to look like the second picture.
Thank you in advance! And sorry if this isn't super clear.
Sean
  4 Commenti
Sean Morgan
Sean Morgan il 20 Giu 2024
I have tried, as shown in the following code, but when I do that the green and yellow RGB image doesn't show through the contour plot.
figure();
ax1=axes;
im=imagesc(ax1,lonlim_local,latlim_local_inv,A);
colormap(ax1,c_map2) % c_map is the brown to black and then c_map2 is yellow to green
set(gca,'YDir','normal')
colorbar(ax1)
hold on
ax2 = axes('position', ax1.Position);
contourf(ax2,m_lon,m_lat,m_bath',[0 -25 -50 -100 -200 -300], 'ShowText','on' ,"FaceAlpha",0);
colormap(ax2,c_map)
hold on
fontsize(16,"points")
contourf(ax2,m_lon,m_lat,m_bath','LevelList',-0.5,'LineColor','black'); %
ylim(latlim_local)
xlim(lonlim_local)
hold on
r1=plot(ax2,shlw_rgn.("Lon (deg)"),shlw_rgn.("Lat (deg)"), 'LineWidth',5, "DisplayName","Near-shore Region");
hold on
r2=plot(ax2,zzg_rgn.("Lon (deg)"),zzg_rgn.("Lat (deg)"), 'LineWidth',5, "DisplayName","Off-shore Region");
hold on
r3=plot(ax2,rtrn_rgn.("Lon (deg)"),rtrn_rgn.("Lat (deg)"), 'LineWidth',5, "DisplayName","Return Region");
legend([r1 r2 r3]);
hold on
xlabel('Longitude (°)');
ylabel('Latitude (°)');
ax3=axes('Position',[.15 .125 .15 .275]);
box on
contourf(ax3,i_lon,i_lat,i_bath','LevelList',0,'LineColor','black');
colormap(ax3,c_map)
text(-82.5, 49, "Canada");
text(-87.5, 38, {"United", "States"});
hold on
plot(shelf)
set(gca,'XTick',[], 'YTick', [])

Accedi per commentare.

Risposta accettata

Sean Morgan
Sean Morgan il 20 Giu 2024
I figured it out. I had to define axis targets as well as set the axis background color to 'none' and then align the axis limits.
Thanks!

Più risposte (0)

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by