Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8043491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:55:01+00:00 2026-06-05T04:55:01+00:00

I have a dataset of 640 points, but plotting it in subplot scales the

  • 0

I have a dataset of 640 points, but plotting it in subplot scales the axis to 700. How do I set the x axis to range from 0 to 640 itself instead of scaling?

Generally, how do I set the axes to arbitary measures? Please explain the options to set the axes.


Here is the code I am using:

    self.figure = Figure()
    self.figure.set_size_inches( (15,3) )
    self.figure.set_dpi(80)

    self.picture = self.figure.add_subplot(211)
    #self.picture.xlim(xmax=640)
    self.intensity = self.figure.add_subplot(212)

self.picture.imshow(pic)
#... where projection happens to be 640 px wide
self.intensity.plot(projection)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:55:03+00:00Added an answer on June 5, 2026 at 4:55 am

    First some setup code to follow along:

    import numpy as np
    import matplotlib.pyplot as plt
    
    figure, (picture, intensity) = plt.subplots(nrows=2, figsize=(15, 3))
    figure.set_dpi(80)
    picture.imshow(np.random.uniform(size=(5, 50)))
    intensity.plot(np.random.random(size=641))
    

    Note the call to plt.subplots (the s at end is important; there’s a different function without the s) requires matplotlib 1.1 or greater. But your original example setup works as well. Also note that the axis is scaled to 700 instead of 640 because matplotlib would prefer to draw a tick at 700 and figures the extra white space isn’t such a big deal.

    Edit: I just wanted to point out the figsize parameter, dpi setting, and picture axes have nothing to do with the original issue, but I added them to match the original example.

    As Chris mentions, you can call

    intensity.set_xlim((0, 640))
    

    You can instead pass in a keyword argument to only tweak the desired parameter:

    intensity.set_xlim(right=640)
    

    If you know that you want tight axis limits, but don’t want to set it manually, the axes object can figure it out based on the data that’s been plotted.

    intensity.autoscale(tight=True)
    

    Or if you only want to scale the x-axis:

    intensity.autoscale(axis='x', tight=True)
    

    Note autoscale is special because it will readjust if your data limits change (e.g. if you plot another data set that has 680 points).

    Alternatively, you can use the margins method:

    intensity.margins(0)
    

    This sets both x and y axis limits to the data limits and adds the specified padding—in this case, 0. If you actually want some spacing in the y-direction then you can write:

    intensity.margins(0, 0.1)
    

    which adds spacing equal to 10% of the y data-interval. These functions all do what you want, but their different call signatures (and behaviors) are useful in different situations.

    Edit: fixed keyword argument to set_xlim based on Chris’s suggestion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset with just 1 datatable and 1 row but with 2
I have a dataset consisting of a large collection of points in three dimensional
I have a dataset that returns questions and answers from the database, each answer
I have dataset with 00:00:00,00:00:15... how to set it to be the timePeriod Expression
I have a dataset that I read in from a complex xml structure.... here
i have Dataset ds DataSet ds = new DataSet(); SQL = SELECT * FROM
I have a dataset from a complex query which I've selected into a temp
The dataset have tables and columns details got from the XML file.I want to
I have a dataset of 2D points (~500k of them) on which I'd like
I have a DataSet that I fill with values from a XML-file. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.