Prevent last xlabel entry getting cut-off after adjusting xlim (2024)

2 views (last 30 days)

Show older comments

JS on 23 May 2020

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim

Commented: JS on 24 May 2020

Open in MATLAB Online

Hi,

So I'm trying to either:

  1. Prevent the last xlabel entry (12) from getting cut-off without increasing the range set using xlim as shown in the first image below.
  2. If were to adjust xlim in order to include the last xlabel entry, is there a way to either stretch out my plot to fill in the white space where my plot ends and still keep the last xlabel entry (12) as shown in the second image below.

This is my current script for generating the plots. The only thing I change to generate the plots shown in the images below is xlim:

%% Making Plot %%

clear

clc

close all

filename='fm.xlsx';

[A]=importdata(filename);

figure

hold on

for i = 1:5

plot(A(:,i),'LineWidth',1.5)

end

xlim([0 9000]) %the line I change either using xlim([0 9000]) or xlim([0 8640]), I have a total 8640 data points

ylim([0 1.0])

% axis([0 8640 0 1])

% axis tight

axis fill

box off;

xlims = get(gca,'XLim');

ylims = get(gca,'YLim');

line(xlims,[ylims(2) ylims(2)],'Color','black','LineWidth',1.5);

line([xlims(2) xlims(2)],ylims,'Color','black','LineWidth',1.5);

set(gca,'XMinorTick','on')

set(gca,'YMinorTick','on')

set(gca,'linewidth',1.5)

set(gca,'XTickLabel',{'';'4';'';'8';'';'9';'';'10';'';'12'})

size(get(gca,'XTick'))

Prevent last xlabel entry getting cut-off after adjusting xlim (2)

Prevent last xlabel entry getting cut-off after adjusting xlim (3)

Thanks!

6 Comments

Show 4 older commentsHide 4 older comments

Tommy on 24 May 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859823

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859823

Your data ends around x = 11.6, so I don't see how you could display 12 on the x axis while having your data extend all the way to the end of the axis. What are you hoping it will look like?

Or maybe you want to plot your data over a range of x values which ends at 12, rather than over the indices as you are currently doing?

JS on 24 May 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859863

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859863

Yea, I'm trying to have my plot look like the first image while having my xlabel entry, 12, remain on the x-axis. I don't have any ideas right now or if it's even possible.

Tommy on 24 May 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859968

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859968

Edited: Tommy on 24 May 2020

Open in MATLAB Online

Ok, so it sounds like you want the final data values to be plotted at x = 12. Assuming the first data values should still be plotted at x = 0, does this work?

X = linspace(0, 12, size(A,1));

for i = 1:5

plot(X, A(:,i),'LineWidth',1.5)

end

No need to set the x limits then.

Plotting over the desired x range is simpler than plotting over indices and then updating the tick labels to display the desired x range. After all, what if the resolution of your signal increased and you were left with 10 times as many points? You are hard-coding in xlim([0 8640]), but if your signal had 86400 points, then you would crop out all but the first tenth of your data.

JS on 24 May 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859988

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859988

Unfortunately it didn't work. Here's what I got when I tried it:

Prevent last xlabel entry getting cut-off after adjusting xlim (8)

So with your input, my last datapoint was plotted at x = 12. However, in the image above is exactly what I'm trying to plot. The reason for trying create one like the above image, is that the data I'm plotting is a convergence plot for figure of merit as a function of rotor revolutions (revs), in which x = 12 is the 12th rotor revolution (works out to be 8,640 time steps in my simulation) in my convergence plot.

Tommy on 24 May 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859998

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_859998

Oh I see, I missed that the axis wasn't scaled linearly. You can still set the tick labels afterwards.

JS on 24 May 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_860918

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/531583-prevent-last-xlabel-entry-getting-cut-off-after-adjusting-xlim#comment_860918

Thanks Tommy! Much appreciated. Got the end result I was looking for:

Prevent last xlabel entry getting cut-off after adjusting xlim (11)

Sign in to comment.

Sign in to answer this question.

Answers (0)

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsAnimation

Find more on Animation in Help Center and File Exchange

Tags

  • xlim
  • xlabel
  • axis
  • xticks
  • axes
  • last entry
  • stretch
  • fill
  • white space
  • plot

Products

  • MATLAB

Release

R2020a

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.


Prevent last xlabel entry getting cut-off after adjusting xlim (12)

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

Prevent last xlabel entry getting cut-off after adjusting xlim (2024)
Top Articles
Kristallnacht: The Night That Signalled the Start of the Holocaust
The Night of the Pogrom
Citi Trends Watches
Sharp Urgent Care Wait Times
Zachary Zulock Linkedin
Shadle Park big-play combo of Hooper-to-Boston too much for Mt. Spokane in 20-16 win
Wharton County Busted Newspaper
Saxies Lake Worth
FREE Houses! All You Have to Do Is Move Them. - CIRCA Old Houses
Job Shop Hearthside Schedule
Gas Buddy Prices Near Me Zip Code
8 Restaurant-Style Dumpling Dipping Sauces You Can Recreate At Home
Roadwarden Thais
Localhotguy
The Closest Dollar Store To My Location
Best Transmission Service Margate
Hướng Dẫn Trade Bittrex
Teenbeautyfitness
Eztv Ig
Fit 4 Life Murrayville Reviews
Banned in NYC: Airbnb One Year Later
Estrella Satánica Emoji
Crete Il Forum
Carefirst.webpay.md
Ethiopia’s PM pledges victory in video from front line
Amanda Bellaci
Adopting Remote UniFi Devices with Windows Server DHCP – itramblings
How to Be an Extra in a Movie (and What to Expect)
Check Subdomains Of A Domain
Craigslist Lubbick
Daily Journal Obituary Kankakee
Pokerev Telegram
Claw Machine Random Name Picker
Cyberpunk 2077 braindance guide: Disasterpiece BD walkthrough
The Anthem Tonight
201-654-6727
Nationsotc.com/Bcbsri
Help with Finding Parts for Your Vehicle
Crystal Westbrooks Nipple
Tmz Jennette Mccurdy And Joe
Musc Food Truck Schedule
FedEx zoekt een Linehaul Supervisor in Duiven | LinkedIn
Aid Office On 59Th Ashland
Coacht Message Boards: A Comprehensive - Techbizcore
Telegram No Limit Groups - Telegram Rocket
Used Cars For Sale in Pretoria | Quality Pre-Owned Cars | Citton Cars
Thekat103.7
Water Temperature Robert Moses
Watch Races - Woodbine Racetrack
What Does Wmt Contactless Mean
Subway Surfers Unblocked Games World
Latest Posts
Article information

Author: Ms. Lucile Johns

Last Updated:

Views: 5705

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Ms. Lucile Johns

Birthday: 1999-11-16

Address: Suite 237 56046 Walsh Coves, West Enid, VT 46557

Phone: +59115435987187

Job: Education Supervisor

Hobby: Genealogy, Stone skipping, Skydiving, Nordic skating, Couponing, Coloring, Gardening

Introduction: My name is Ms. Lucile Johns, I am a successful, friendly, friendly, homely, adventurous, handsome, delightful person who loves writing and wants to share my knowledge and understanding with you.