How can I draw a frame around the inset plot? (2024)

74 views (last 30 days)

Show older comments

Sim about 17 hours ago

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot

Commented: Sam Chak about 12 hours ago

Accepted Answer: Star Strider

Open in MATLAB Online

How can I draw a frame around the inset plot?

x1 = linspace(0,1);

x2 = linspace(3/4,1);

y1 = sin(2*pi*x1);

y2 = sin(2*pi*x2);

figure(1)

% plot on large axes

plot(x1,y1)

% create smaller axes in top right, and plot on it

axes('Position',[.6 .6 .2 .2])

box on

plot(x2,y2)

How can I draw a frame around the inset plot? (2)

My desired output is the following one:

How can I draw a frame around the inset plot? (3)

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Star Strider about 15 hours ago

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#answer_1509074

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#answer_1509074

Open in MATLAB Online

Use an annotation object —

x1 = linspace(0,1);

y1 = sin(2*pi*x1);

y2 = sin(2*pi*x2);

figure(1)

% plot on large axes

plot(x1,y1)

Ax1 = gca;

pos1 = Ax1.Position;

% create smaller axes in top right, and plot on it

Ax2 = axes('Position',[.6 .6 .2 .2]);

box on

plot(x2,y2)

pos2 = Ax2.OuterPosition;

a2 = annotation('rectangle', pos2);

a2.Color = 'r';

a2.LineWidth = 2;

How can I draw a frame around the inset plot? (5)

.

7 Comments

Show 5 older commentsHide 5 older comments

Sim about 13 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3251894

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3251894

Edited: Sim about 13 hours ago

Thanks both @Star Strider and @Jaimin!! Very nice answers! :-) .......I do not know which one to accept since they are similar and both efficient :-) I would accept both of them :-)

Star Strider about 13 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3251899

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3251899

My pleasure!

Image Analyst about 12 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3251974

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3251974

@Sim There's a "solution" for that, kind of. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points. So an Accept for one will earn that person 4 points, and a Vote for the other will award that person 2 points. If they're equally good answers in your eyes, then you can ask the one you accepted, or someone else, to Vote for the one you voted for to award an additional 2 points.

For full details on how to earn reputation points see: https://www.mathworks.com/matlabcentral/answers/help?s_tid=al_priv#reputation

Sim about 11 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252004

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252004

thanks a lot @Image Analyst :-) I voted their answers :-)

I did not understand very well

"If they're equally good answers in your eyes, then you can ask the one you accepted, or someone else, to Vote for the one you voted for to award an additional 2 points."

since I did not accept any answer yet... but of course, if anyone has suggestions on which answer to accept, I will follow those suggestions :-)

Image Analyst about 10 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252054

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252054

To explain further, Accept and Vote are two different icons/actions you can do. You can only accept one answer but you can vote for as many as you like. If you think both answers are the same, and want to award the same number of points to both (4 points), then you can Accept the answer from person #1 and Vote for the answer from person #2. So now #1 has 4 points and #2 has only 2 points. But you can ask #1, or me or anyone, to Vote for #2. That will add an additional 2 points to #2, now giving person #2 a total of 4 points - the same as #1 (who you accepted).

They both gave code samples and used annotation but @Jaimin's code had more/better comments so that might give him the edge. However a lot of people just paste your question into an AI engine and paste it here. The AI answers almost always have words in it like "I understand that you want to...". I'm not saying @Jaimin's was an AI answer, but that phrase is a red flag for AI for many of us. Not that AI answers are worse than human answers - in many cases they give better answers than humans - it's just something to consider.

Sim about 10 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252094

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252094

Very clear, thanks a lot! To be honest, I got the same feeling about a possible AI anwer... OK, lets do as suggested... I accept one answer and I hope people can upvote the ather one to equally recognise both answers... :-)

Sam Chak about 10 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252104

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252104

I would evaluate which solution provides a more aesthetically pleasing red frame that closely matches the reference. Let @Sim decide.

How can I draw a frame around the inset plot? (13)

Sign in to comment.

More Answers (1)

Jaimin about 15 hours ago

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#answer_1509029

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#answer_1509029

Open in MATLAB Online

Hi @Sim

Based on the description, I understand that you want to add a frame around the inset plot in the figure, as shown below.

How can I draw a frame around the inset plot? (15)

Below is the sample code to meet the requirement.

x1 = linspace(0,1);

x2 = linspace(3/4,1);

y1 = sin(2*pi*x1);

y2 = sin(2*pi*x2);

figure(1)

% Plot on large axes

plot(x1, y1)

% Create smaller axes in top right, and plot on it

inset_axes = axes('Position', [.6 .6 .2 .2]);

plot(x2, y2)

% Get the current position of the inset axes

pos = inset_axes.Position;

% Adjust the position to make the rectangle slightly larger

margin = 0.01; % Adjust this value to change the size of the margin

new_pos = [pos(1) - margin, pos(2) - margin, pos(3) + 2*margin, pos(4) + 2*margin];

% Add a red box around the inset plot

annotation('rectangle', new_pos, 'Color', 'r', 'LineWidth', 2);

How can I draw a frame around the inset plot? (16)

Please refer this MathWorks Documentation to understand “annotation”

Annotation:

https://www.mathworks.com/help/matlab/ref/annotation.html

I hope this will be helpful.

1 Comment

Show -1 older commentsHide -1 older comments

Sim about 10 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252099

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2149534-how-can-i-draw-a-frame-around-the-inset-plot#comment_3252099

Edited: Sim about 10 hours ago

Thanks @Jaimin! I would like to accept both your's and @Star Strider answer.. And following the @Image Analyst suggestions, I accepted the @Star Strider answer and I asked people to upvote yours, so that you will be equally awarded as @Star Strider (i.e. with the same score) :-)

Sign in to comment.

Sign in to answer this question.

See Also

Tags

  • frame
  • axis
  • inset
  • plot

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How can I draw a frame around the inset plot? (18)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How can I draw a frame around the inset plot? (2024)
Top Articles
Gordon Ramsay's best Christmas recipes
15 Warm Winter Vegan Soup Recipes | Aglow Lifestyle
Use Copilot in Microsoft Teams meetings
Spectrum Gdvr-2007
Average Jonas Wife
Time in Baltimore, Maryland, United States now
Brady Hughes Justified
Kansas City Kansas Public Schools Educational Audiology Externship in Kansas City, KS for KCK public Schools
Kaydengodly
Lifebridge Healthstream
The 10 Best Restaurants In Freiburg Germany
Triumph Speed Twin 2025 e Speed Twin RS, nelle concessionarie da gennaio 2025 - News - Moto.it
Craigslist Parsippany Nj Rooms For Rent
Autobell Car Wash Hickory Reviews
How to Type German letters ä, ö, ü and the ß on your Keyboard
Umn Pay Calendar
Visustella Battle Core
Swimgs Yung Wong Travels Sophie Koch Hits 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Springs Cow Dog Pig Hollywood Studios Beach House Flying Fun Hot Air Balloons, Riding Lessons And Bikes Pack Both Up Away The Alpha Baa Baa Twinkle
Day Octopus | Hawaii Marine Life
Think Up Elar Level 5 Answer Key Pdf
The ULTIMATE 2023 Sedona Vortex Guide
Christina Khalil Forum
How Much Are Tb Tests At Cvs
Gem City Surgeons Miami Valley South
Roll Out Gutter Extensions Lowe's
Kirksey's Mortuary - Birmingham - Alabama - Funeral Homes | Tribute Archive
Samantha Aufderheide
Rufus Benton "Bent" Moulds Jr. Obituary 2024 - Webb & Stephens Funeral Homes
Touchless Car Wash Schaumburg
Aol News Weather Entertainment Local Lifestyle
eugene bicycles - craigslist
Miles City Montana Craigslist
Spectrum Outage in Queens, New York
12657 Uline Way Kenosha Wi
Umn Biology
TJ Maxx‘s Top 12 Competitors: An Expert Analysis - Marketing Scoop
Christmas Days Away
Smartfind Express Henrico
CARLY Thank You Notes
Case Funeral Home Obituaries
Trivago Myrtle Beach Hotels
What Does Code 898 Mean On Irs Transcript
Levothyroxine Ati Template
My Locker Ausd
Ursula Creed Datasheet
COVID-19/Coronavirus Assistance Programs | FindHelp.org
Pixel Gun 3D Unblocked Games
Willkommen an der Uni Würzburg | WueStart
Learn4Good Job Posting
Hughie Francis Foley – Marinermath
Where To Find Mega Ring In Pokemon Radical Red
Bomgas Cams
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6558

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.