How to create a rectangle to locate a zooming area in a plot?
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Giuseppe
am 26 Feb. 2022
Beantwortet: Abolfazl Chaman Motlagh
am 26 Feb. 2022
Hi guys!
I created an additional box within my figure to zoom a particular area of interest. I put this box in a position as desired. Now I want to create a rectangle within my figure to identify the coordinates of the zoom.
I want to get something like the blue rectangle in the following figure:
Can you help me?
Here is my script and attached to this post the required files:
%Planar Lyapunov Orbits (SE system, L1 point)
clear all; close all; clc;
%Data import
% Definition of path names and file names
Input_path_Fortran = 'D:\OneDrive\MSc_Thesis\Projects\Planar_Lyapunov_orbits\InputFiles\';
Output_path_Fortran = 'D:\OneDrive\MSc_Thesis\Projects\Planar_Lyapunov_orbits\OutputFiles\';
filename_Ly_orb = 'Planar_Lyapunov_SE_L1.txt';
filename_Ly_orb_selected = 'Planar_Lyapunov_SE_L1_evenly_spaced.txt';
%Import original database containing 4182 orbits
Ly_orb = import_txt_file([Input_path_Fortran,filename_Ly_orb],1,inf);
%Import filtered data containing 50 orbits
Ly_orb_sel = import_txt_file([Output_path_Fortran,filename_Ly_orb_selected],2,inf);
%Plots
load("Customized_colors.mat");
% Trova un modo per trasferire le opzioni di grafica di una figura a
% un'altra senza ripetere i comandi all'interno del plot (color, marker, et..)
figure
plot(Ly_orb.x0,Ly_orb.JacobiConstant,'.','color',my_cyan,'MarkerFaceColor'...
,my_cyan,'MarkerSize',2); hold on
plot(Ly_orb_sel.x0,Ly_orb_sel.JacobiConstant,'.','color',my_red,'MarkerFaceColor'...
,my_red,'MarkerSize',8); hold on
yline(Ly_orb_sel.JacobiConstant,'color',my_red,'LineStyle',":");
grid off;
xlabel('$x_0$','interpreter','latex','fontsize',12);
ylabel('$Jacobi\ Constant$','interpreter','latex','FontSize',12);
lgd = legend('$Original\ database$','$Filtered\ database$',...
'Orientation',"vertical",'Location',"northwest");
lgd.Interpreter = 'latex';
lgd.FontSize = 11;
% Zoom on a casual portion of figure to show the equally spaced Jacobi constant values
axes('position',[.63 .16 .25 .25])
box on % put box around new pair of axes
x_min = -0.9930;
x_max = -0.9925;
indexOfInterest = (Ly_orb.x0 < x_max) & (Ly_orb.x0 > x_min);
indexOfInterest_sel = (Ly_orb_sel.x0 < x_max) & (Ly_orb_sel.x0 > x_min);
plot(Ly_orb.x0(indexOfInterest),Ly_orb.JacobiConstant(indexOfInterest),...
'.','color',my_cyan,'MarkerFaceColor',my_cyan,'MarkerSize',2); hold on
plot(Ly_orb_sel.x0(indexOfInterest_sel),Ly_orb_sel.JacobiConstant(indexOfInterest_sel),...
'.','color',my_red,'MarkerFaceColor',my_orange,'MarkerSize',8); hold on
%yline(Ly_orb_sel.JacobiConstant(indexOfInterest_sel),'color',my_red,'LineStyle',":");
axis tight
0 Kommentare
Akzeptierte Antwort
Abolfazl Chaman Motlagh
am 26 Feb. 2022
in first axes use function rectangle.
y_min = min(Ly_orb.JacobiConstant(indexOfInterest)); % need indexofInterest for this
y_max = min(Ly_orb.JacobiConstant(indexOfInterest));
width = x_max-x_min;
height = y_max-y_min;
ROI_Position = [x_min y_min width height];
rectangle('Position',ROI_Position,'EdgeColor','b','LineWidth',0.5);
if you can select your axes. rectangle can get axes as input.
rectangle(axes,...)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Properties 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!