![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1469506/image.png)
Using an geographic plot as a background for other matlab plots
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
HI,
I have an geographic plot with two latitude and Longitude information, I am able to get the actual plot as expected.
f = figure()
lat = [48.2402500000000 48.285059599999980];
lon = [16.2759199000000 16.179709699999990];
geoplot(lat,lon,'-o');
Can Anyone please help me out how can i save the above image and use as an background for other matlab plot.
When i tried using the command, "I = imread('test1.png');" i was able to save it but in further i was not bale to add it as a background to other plots.
Expecting for the answer thank you.
0 Commenti
Risposte (1)
Narvik
il 31 Ago 2023
Hi,
You can accomplish this by creating the required MATLAB plot and then plotting the saved background image using the “image” function. Using the "uistack" function, the image can be placed in the plot's background.
Please find the working code below
% geoplot
f = figure();
lat = [48.2402500000000 48.285059599999980];
lon = [16.2759199000000 16.179709699999990];
gp = geoplot(lat,lon,'-o');
% removing labels and ticks
% for a clean background image
gx = gp.Parent;
gx.LatitudeLabel.String = '';
gx.LongitudeLabel.String = '';
gx.LatitudeAxis.TickLabels = {};
gx.LongitudeAxis.TickLabels = {};
% exporting the plot as a png
exportgraphics(f, 'geoplot.png');
% plotting a line
x = 0:pi/100:2*pi;
y = sin(x);
plot(x, y, 'r');
axis tight;
% setting the background image
hold on;
% loading the image
I = imread('geoplot.png');
% plotting the image with the
% x, y coordinates of the image's
% boundaries as the current axis' limits
% flipping ylim as some images may
% be flipped in the vertical direction
h = image(xlim,flip(ylim),I);
% sending the image to bottom of stack
uistack(h,'bottom');
The output of the code is as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1469506/image.png)
For more information on the “image” and “uistack” functions, you can refer to the following documentation:
Hope this helps!
Vedere anche
Categorie
Scopri di più su Geographic Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!