How do I plot a circle on a Matlab figure?

22 views (last 30 days)
Harsh Rangwala
Harsh Rangwala on 23 Jan 2023
Commented: Gael Goron on 2 Feb 2023
I want to plot a circle with blinking effect on a Matlab figure. I want this marker on the simulation to have a blinking effect everytime my readings are above threshold value. Is there any function or way to achieve this?
So far I have tried:
Using this creates a separate figure, which I don't want:
plot(0,0,'ro','MarkerSize',10,'MarkerFaceColor','r','MarkerEdgeColor','r');
I want to create a plot on the figure which is created by this code:
viewer = trackingGlobeViewer('Basemap','streets-dark',...
'TrackLabelScale',1.3,'TrackHistoryDepth',4000,...
'CoverageMode','Coverage');
For instance I want to plot a marker at the bottom right of this figure generated by the above code.
EDIT:
Thank you!

Answers (2)

Gael Goron
Gael Goron on 1 Feb 2023
Hi,
The trackingGlobeViewer is based on the same technology as geoglobe from the Mapping Toolbox. Globe based visualizations are not like the usual MATLAB graphics plots, you cannot use 'plot' to overlay graphics on top of a globe.
If you have the Mapping Toolbox, you can use geoplot3 instead.
First create the trackingGlobeViewer as in the example:
viewer = trackingGlobeViewer('Basemap','streets-dark',...
'TrackLabelScale',1.3,'TrackHistoryDepth',4000,...
'CoverageMode','Coverage');
To retrieve the geoglobe object you can use either one of the following lines of code:
globe = findall(groot, 'type', 'globe');
globe = viewer.Globe; %Undocumented
% Next plot markers with geoplot3
% geoplot3(globe, ...)
  2 Comments
Harsh Rangwala
Harsh Rangwala on 2 Feb 2023
Can I use Geoplot to plot a text or a marker that alywas stays at a particular position on my tackGlobeViewer??
Gael Goron
Gael Goron on 2 Feb 2023
Yes you can plot a marker with geoplot3, it would look like this for instance (see the documentation link from my previous post for more details).
geoplot3(globe, 71,-42,10,'Color','r','MarkerSize',13,'Marker','o');
Note that by default, the geoplot3 command will move the globe camera to the location of the markers. If you do not want this behavior, you can disable it by setting the camera modes to manual like this:
% Disable camera first
campitch(globe,'manual')
camroll(globe,'manual')
camheading(globe,'manual')
campos(globe,'manual')
camheight(globe,'manual')
% Plot marker
geoplot3(globe, 71,-42,10,'Color','r','MarkerSize',13,'Marker','o');
The marker will stay at this particular location on the globe, because the default option for NextPlot is 'add'. If you need to clear the marker, you can set NextPlot to 'replace'.
There is currently no capability to display text on the globe, but I can pass along this information to the Mapping Toolbox team.

Sign in to comment.


Walter Roberson
Walter Roberson on 23 Jan 2023
plot(0,0,'ro','MarkerSize',10,'MarkerFaceColor','r','MarkerEdgeColor','r');
That could have several different effects.
  • If you have no figures of any kind opened, or if you do have figures open but none of them are the "current" figure, then a new traditional figure would be opened and a new axes placed in the new traditional figure, and the marker would be plotted in that axes
  • If you have uifigure() open but not traditional figures, then by default the handle visibility is set off for uifigure() so plot() would not be able to locate the uifigure as being the current figure; this then becomes the same as the above where a new traditional figure is created
  • if you have a "current" (visible) figure that has no "current" axes, then a new axes would be created in the figure and the marker would be plotted in the new axes
  • if you have a "current" (visible) axes whose "NextPlot" property is set to "replace" (the default if you have not used "hold on") then the axes will be cla() but not cla('reset') -- the plot of the marker would replace the current plot
  • if you have a "current" (visible) axes whose "NextPlot" is not "replace" then the plot of the marker would be added at layer z = 0 without removing any current drawing
These days the most common reason that a plot() creates a new figure is if you are using App Designer: when you use App Designer you should always tell plot() explicitly which existing axes you want to draw into (because the handle visibility of the UIAxes will be off and plot() will not be able to find the axes when it does gca() )
  14 Comments
Harsh Rangwala
Harsh Rangwala on 24 Jan 2023
It is possible that this might be implemented in HTML or some web development framework. You don't think there is any other way to create an alert on the viewer itself?
Walter Roberson
Walter Roberson on 24 Jan 2023
I do not know; I would need to poke around the internals more, but I do not have that toolbox.
Perhaps it is time to consider using annotation . Annotations live in a transparent graphics pane above all of the other panes (so they should always be on top.) Because they do not live inside axes, the position coordinates for annotation default to being normalized relative to the figure . You can change the units, but you cannot change the units to data coordinates

Sign in to comment.

Categories

Find more on Geographic Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!