
How to add custom images as markers?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?

0 Kommentare
Antworten (1)
Image Analyst
am 7 Apr. 2019
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);

1 Kommentar
Image Analyst
am 7 Apr. 2019
Bearbeitet: Image Analyst
am 7 Apr. 2019
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.
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!