How to add custom images as markers?

조회 수: 6 (최근 30일)
OB
OB 2019년 4월 7일
편집: Image Analyst 2019년 4월 7일
I want to represent aircraft formations graphically, in a 2D plane, I have a function that produces the position given spacing information and the number of aircraft. At the moment I am doing this with conventional markers in the plot function (samples shown below). Is it possible to place images in place of the markers?

답변 (1개)

Image Analyst
Image Analyst 2019년 4월 7일
See this code and adapt as needed (i.e. supply your own image, turn axes labels off, etc.)
% Draw a small image inset in the upper right corner of a larger plot.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
x = linspace(0, 1);
y1 = sin(2*pi*x);
figure(1)
% plot on large axes
plot(x, y1, 'LineWidth', 2)
grid on;
ax1 = gca; % Store handle to axes 1.
% Create smaller axes in top right, and plot on it
% Store handle to axes 2 in ax2.
ax2 = axes('Position',[.6 .6 .3 .3])
box on;
fileName = 'peppers.png';
rgbImage = imread(fileName);
imshow(rgbImage);
axis('on', 'image');
% Now draw something back on axis 1
hold(ax1, 'on'); % Don't blow away existing curve.
y2 = cos(2*pi*x/0.7);
plot(ax1, x, y2, 'r-', 'LineWidth', 2);
Capture.PNG
  댓글 수: 1
Image Analyst
Image Analyst 2019년 4월 7일
편집: Image Analyst 2019년 4월 7일
OK, here's a little closer to what you want:
x = linspace(0, 1, 10);
y = sin(2*pi*x);
figure(1)
% plot on large axes
plot(x, y, 'bv', 'LineWidth', 2)
grid on;
% Put images at every (x,y) location.
fileName = 'peppers.png';
rgbImage = imread(fileName);
for k = 1 : length(x)
% Create smaller axes on top of figure.
xImage = x(k);
yImage = y(k);
ax2 = axes('Position',[xImage, yImage, .05 .05])
box on;
imshow(rgbImage);
axis('off', 'image');
end
though I'm not sure how to get the coordinates right since the axes Position property seems to use coordinates of the whole parent figure, not of the axes that's under the image axes which you're placing. I don't know how to compensate for that - you'll have to play around with it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by