Set Image Axis as Primary Axis

3 visualizzazioni (ultimi 30 giorni)
Josh Bridges
Josh Bridges il 11 Mar 2020
Commentato: Josh Bridges il 13 Mar 2020
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 Commenti
Ameer Hamza
Ameer Hamza il 11 Mar 2020
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 il 12 Mar 2020
Josh, check the code in my updated answer.

Accedi per commentare.

Risposta accettata

Ameer Hamza
Ameer Hamza il 11 Mar 2020
Modificato: Ameer Hamza il 12 Mar 2020
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 Commenti
Ameer Hamza
Ameer Hamza il 13 Mar 2020
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 il 13 Mar 2020
Thanks for this!
I'll try and apply it to the above plot.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by