필터 지우기
필터 지우기

Using an geographic plot as a background for other matlab plots

조회 수: 20 (최근 30일)
Charan
Charan 2023년 8월 18일
댓글: Charan 2023년 9월 4일
HI,
I have an geographic plot with two latitude and Longitude information, I am able to get the actual plot as expected.
f = figure()
f =
Figure (1) with properties: Number: 1 Name: '' Color: [1 1 1] Position: [671 558 577 433] Units: 'pixels' Show all properties
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.

답변 (1개)

Narvik
Narvik 2023년 8월 31일
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:
For more information on the “image” and “uistack” functions, you can refer to the following documentation:
Hope this helps!

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by