Adding legend to geoglobe with several geoplot3 lines
41 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Julian Dönges
el 14 de Sept. de 2020
Respondida: Steve Schaefer
el 5 de Oct. de 2020
How can I add a legend to a geoglobe with several geoplot3 lines?
0 comentarios
Respuesta aceptada
Vinai Datta Thatiparthi
el 17 de Sept. de 2020
Editada: Vinai Datta Thatiparthi
el 17 de Sept. de 2020
Hey Julian,
MATLAB at present does not support adding legends to geoglobe. I noticed that this request was already brought to the attention of the concerned parties. They may investigate the matter further.
Presently, as a workaround, consider using the uigridlayout function to create a separate grid, where one grid can be used to display the geoglobe plots and the other grid for displaying the text and legends. In the second grid, you could use the uiaxes function to create an axes and title for the contours and legend. Further, you could use the legend function to create the legends for the geoplots & the drawnow function to ensure that the legend is drawn with the desired colors.
Hope this helps!
Más respuestas (1)
Steve Schaefer
el 5 de Oct. de 2020
Legend in Geographic Globe - Details on uigridlayout & uipanel Workaround
An example to illustrate the workaround required to add a legend for geoglobe with multiple geoplot3 lines based on uigridlayout created with MATLAB R2020b.
fig1 = uifigure;
uig = uigridlayout(fig1, [1 2]);
uig.ColumnWidth = {'1x',100};
uig.RowHeight = {300,'1x'};
The right column will use a constant width of 100 pixel and the left column will fit to the available space. It is important to set a fixed RowHeight, to avoid resizing of the axes object and the embedded legend. See the uigridlayout documentation for furher information.
Note: GridLayout does not support GeographicGlobe. Create a panel container as a child of the GridLayout using uipanel, and then place the GeographicGlobe in the panel.
uipLeft = uipanel(uig,"BackgroundColor",fig1.Color,"BorderType","none");
uipLeft.Layout.Row = [1 2];
gg = geoglobe(uipLeft,"Terrain","gmted2010");
Plot the data on the geoglobe object
This is the data we use for plotting, assuming we want to use geplot3 on the GeographicGlobe and different altitudes for color coding.
trk = gpxread('sample_mixed','FeatureType','track');
lat = trk.Latitude;
lon = trk.Longitude;
ele = trk.Elevation;
This runs over all altitudes, but could also be any set of lines we want to plot. Use random colors for demo purposes.
targetAltitudes = [3000 4000 5000];
hold(gg,'on')
for tgtAlt = targetAltitudes
geoplot3(gg,lat,lon,tgtAlt, ...
'HeightReference','geoid', ...
'LineWidth',2,'Color',rand(1,3)); %#ok<SAGROW>
end
Create a legend for Geogrpahic Globe:
uipRight = uipanel(uig, 'Title', 'Legend Panel', ...
'BackgroundColor',fig1.Color,'BorderType','none');
uipRight.Layout.Row = 1;
Alternative: The uigridlayout object could be directly used as axes object parent, but without the nice uipanel title. This approach is not shown here.
ax = axes(uipRight,'Position',[0 0 1 1]);
geoLines = get(gg,'Children');
pl = plot(ax,nan(2,numel(geoLines)));
ax.Visible = 'off';
The below line sets the (custom) colors used with geoplot3:
set(pl,{'Color'},get(geoLines,'Color'));
This line creates the actual legend directly below the pseudo legend title given through the uipanel title.
lgd = legend(ax,pl, 'Location','northwest', ...
'Color','none','Box','off');
The below code sets (if required) custom strings for the legend, here the HeightData Property is referenced.
Note: Adjust the numerical value in uig.ColumnWidth if legend strings are too long.
lgd.String = convertStringsToChars(string(...
get(geoLines,'HeightData')));
0 comentarios
Ver también
Categorías
Más información sobre Geographic Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!