Effacer les filtres
Effacer les filtres

How do I add a legend to a pcolorm map plot?

35 vues (au cours des 30 derniers jours)
Keihan
Keihan le 26 Mar 2018
Commenté : Chad Greene le 9 Juin 2018
Hi, I have draped a 2 dimensional plot over a map using pcolormap:
axesm('mapprojection','miller','maplatlimit',[latMin latMax],...
'maplonlimit',[longMin-5 longMax+5],'grid','on','MeridianLabel','on',...
'ParallelLabel','on','PLineLocation',4,'MlineLocation',8,'LabelUnits','degrees','MLabelLocation',8,...
'LabelFormat','compass','FLatLimit',[40 86]);
geoshow('landareas.shp', 'FaceColor', [1 1 1])
geoshow('worldlakes.shp', 'FaceColor', 'cyan')
[ h] = pcolorm(lat,long,data_rate);
legends = {'50 Mbps','20 Mbps'};
legend(h, legends);
The 2-D array consists of only 2 values. However, the legend command only generated one entry in the legend table. Why doesn't it show the second values. I've attached the

Réponses (2)

Keihan
Keihan le 8 Juin 2018
Hi Chad, Thanks for your response. So what command should I use to display all the items?
  1 commentaire
Chad Greene
Chad Greene le 9 Juin 2018
Oh! So data_rate is a matrix with only two values, you're using pcolorm to plot those two values, and you want the legend to show the two values and their corresponding colors?
Typically I wouldn't use a legend to show the values in a pcolorm map, because I'm usually working with a continuum of values, so colorbar is more appropriate than legend.
I don't know of an elegant solution for what you're trying to do. There are many ways to do it, but they all involve a lot of steps. Using colorbar you could do something like this:
% Here's some sample data:
z = peaks;
z(z>0) = 70;
z(z<=0) = 50;
% plot the data:
pcolor(z)
shading flat
cb = colorbar;
%ylabel(cb,'data rate')
caxis([40 80])
cb.Ticks = [50 70];
cb.TickLabels = {'50 Mbps','70 Mbps'};
colormap(parula(2))
The example above uses pcolor on a cartesian plot instead of pcolorm on a map, but the principles are the same.

Connectez-vous pour commenter.


Chad Greene
Chad Greene le 30 Mai 2018
When you call
legend(h, legends);
the h refers only to the handle of the pcolorm object, so h is the only item that will appear in the legend.

Catégories

En savoir plus sur Geographic Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by