How can I add a legend to a geoglobe with several geoplot3 lines?
MATLAB: Adding legend to geoglobe with several geoplot3 lines
geoglobegeoplot3legendMATLAB
Related Solutions
Update: Using worldmap to initialize the axes and cutting off the command axesm('equazim'...) is a work around, I've found.
The worldmap call makes a polar plot by default for my limits (if it doesn't getm(gca) seems to give a lot of info on what can be adjusted maybe that provides a way...) and it works on an arclength distance from the origin at the pole which is (0,0).
Edit: setm(gca,'mapprojection','eqdazim'); should force polar plot since that's what mine is set to.
The code to make the first plot that doesn't shrink with camera rotation is below (second, long). Some extra bits in gridm were needed to apply basic stuff that axesm('eqaazim') seemed to do - like turning off label rotation. Otherwise it works well and lat/long can be projected on with an arclength formula (below first).
Work around found - but no solution to the weird shrinking plots.
ReAdj = Re*1000*pi/180; %convert Re to meters, toss in the pi/180 conversion needed for degrees as well
coastLines_lat_Circ = (max(plotLatRange)-coastLines_lat).*ReAdj.*sind(coastLines_long-90); %create Y points circular coords
coastLines_long_Circ = (max(plotLatRange)-coastLines_lat).*ReAdj.*cosd(coastLines_long-90); %create X points circular coords
%CREATE THE FIGURE WE WILL USE
fig1 = figure('Color','w','units','normalized','outerposition',[0 0 1 1]); %maximizes figure window, makes it white
fig1Axes = worldmap([min(plotLatRange) , max(plotLatRange)],[min(plotLongRange) , max(plotLongRange)]); %tries to standardize the maps
% fig1Axes = axes('Parent', fig1); %gets a reference to the axes for later
% axesm('eqaazim','MLabelParallel',0,'Origin',gif_OriginCentering,'MapLatLimit',[min(plotLatRange) , max(plotLatRange)]); %ruins it
axis offframem ongridm onmlabel onplabel on; %
setm(gca,'MLabelParallel',0,'FFaceColor', [176/255,196/255,222/255]); %FFaceColor sets ocean color (orig color [.5,.7,.9]) powder blue: [176/255,224/255,230/255]
hMap = geoshow(fig1Axes,coastLines_lat,coastLines_long,'DisplayType','polygon','FaceColor', [0.5 0.7 0.5]);axis equal tight %key for plotScaleFactor (adjusts size slightly...)
gridm('k'); %set grid dotted lines color to black (was sea color..)
gridm('plinelocation',15,'plabellocation',15,'labelrotation','off'); %force latitude numbers each 15 deg
%key for spinning the plot
title('Prep Title'); %fire up the title
fig1Title = get(fig1Axes,'Title'); % handle of title, need it for later b/c rotation moves title location
set(gca, 'fontweight','bold', 'FontSize',18);hold on;plotScaleFactor = max(xlim); %record, plot scale factor (it goes from 0 to a # less than 1)
defaultTitlePosition = get(fig1Title,'Position') + [0 , 0.30*(10^(length(num2str(round(plotScaleFactor)))-1)), 0]; %Set the default title position
set(fig1Title,'Position',defaultTitlePosition); % Shift the position upward
defaultTitlePosition_Mag = norm(defaultTitlePosition); %get mag of the default title position for rotation calcs
fig1Axes_pos = get(fig1Axes,'Position');%PUT THIS CALL AT END SO WEIRD SIZING DOESN'T HAPPEN - way annoying
set(gca, 'CameraViewAngleMode', 'manual'); % 'CameraTargetMode', 'manual', 'CameraPositionMode', 'manual' extra calls that aren't needed for what I want
%NOTE: Typing gca gets you a ton of deets on the plot's settings
There are two things to keep in mind while using the 'geoglobe' function to plot multiple plots:
1. Firstly, the 'geoglobe' function has a default property of deleting existing plots and reset globe properties, except Position and Units, to their default values before displaying the new plot. In order to allow multiple plots to be plotted on the globe the user needs to specify the 'NextPlot' name-value pair argument as 'add' as shown below in the example:
uif = uifigure;g = geoglobe(uif,'NextPlot','add');
Additionally, please refer to the following documentation regarding the NextPlot property:
2. Secondly, only certain 'hold' syntaxes are supported by the 'geoglobe' function as shown below:
hold(g) %toggles the state between off and on
hold(g,'on') % retains plot so that new plots can be added to the same plot
hold(g,'off') % releases the current plot
Please refer to this documentation link which describes the supported 'hold' syntax:
Additionally, please refer to this sample MATLAB code that will demonstrate how to plot multiple line plots over a local region using the 'geoplot3' function:
trk = gpxread('sample_mixed','FeatureType','track');lat = trk.Latitude;lon = trk.Longitude;h = trk.Elevation;lat1 = 0.98*(trk.Latitude);lon1 = 0.98*(trk.Longitude);h1 = 0.98*(trk.Elevation);uif = uifigure;g = geoglobe(uif,'NextPlot','add');geoplot3(g,lat,lon,h,'c')hold(g,'on')mskip = 1:25:length(lat1);geoplot3(g,lat1,lon1,h1,'ro','MarkerIndices',mskip)
Resulting figure:
Best Answer