Adding legend to geoglobe with several geoplot3 lines
43 ビュー (過去 30 日間)
古いコメントを表示
Julian Dönges
2020 年 9 月 14 日
回答済み: Steve Schaefer
2020 年 10 月 5 日
How can I add a legend to a geoglobe with several geoplot3 lines?
0 件のコメント
採用された回答
Vinai Datta Thatiparthi
2020 年 9 月 17 日
編集済み: Vinai Datta Thatiparthi
2020 年 9 月 17 日
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!
その他の回答 (1 件)
Steve Schaefer
2020 年 10 月 5 日
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')));
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/371227/image.jpeg)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Geographic Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!