Set Image Axis as Primary Axis

조회 수: 3 (최근 30일)
Josh Bridges
Josh Bridges 2020년 3월 11일
댓글: Josh Bridges 2020년 3월 13일
I have a figure of a plot/graph I would like to load into MATLAB (first figure below) that has its own axes. I would like to make these axes my working axes as I need to plot data on top of this graph at particular points corresponding to the figure's axis. However, when I load the image, MATLAB generates it's own axis(second figure). If it wasn't for the fact that the figure axis is on a log-log scale, this might not be a problem.
Any help would be appreciated it. Thanks!
  댓글 수: 6
Ameer Hamza
Ameer Hamza 2020년 3월 11일
I recently answered another question dealing with synchronization of axes: https://www.mathworks.com/matlabcentral/answers/509899-plot-with-two-related-x-axes. Although these two cases are not different, however, the basic idea is the same. You can see that answer to come up with a solution. If no one else posted a solution until tomorrow, then I will try to post a solution.
Ameer Hamza
Ameer Hamza 2020년 3월 12일
Josh, check the code in my updated answer.

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 11일
편집: Ameer Hamza 2020년 3월 12일
Following example show how to synchronize the image axis with the MATLAB plot axis
im = imread('image.jpeg');
fig = figure();
h = imshow(im);
ax_img = gca;
ax_plot = axes();
hold(ax_plot);
ax_plot.Color = 'none';
ax_plot.Position = [0.183 0.158 0.678 0.778]; % bit of trial and error
ax_plot.XLim = [1 100];
ax_plot.YLim = [0.005 1];
ax_plot.XScale = 'log';
ax_plot.YScale = 'log';
% Example: give values in image coordinates
plot(ax_plot, [1 5 10 50 100], [0.005, 0.05, 0.1, 0.5, 1], 'r', 'LineWidth', 2);
ax_plot.Visible = 'off';
  댓글 수: 4
Ameer Hamza
Ameer Hamza 2020년 3월 13일
Here is an example for the case when you want to make the axis invisible but keep the labels.
fig = figure();
ax = axes();
hold(ax);
plot(1:10);
ax.XAxis.Visible = 'off';
x_position = cumsum(ax.Position([1 3]));
y_position = ax.Position(2);
num_ticks = numel(ax.XAxis.TickValues);
x_tickLabels = ax.XAxis.TickLabels;
ticks_x_position = linspace(x_position(1)-0.01, x_position(2)-0.02, num_ticks); % subtraction values are based on manual tuning
ticks_y_position = y_position - 0.1;
for i=1:num_ticks
annotation(fig, 'textbox', [ticks_x_position(i), ticks_y_position 0.1 0.1], ...
'String', x_tickLabels{i}, ...
'EdgeColor', 'none');
end
Josh Bridges
Josh Bridges 2020년 3월 13일
Thanks for this!
I'll try and apply it to the above plot.

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by