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

  • SEARCH
  • Home
  • 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 8594563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:13:41+00:00 2026-06-12T00:13:41+00:00

I am trying to fix how python plots my data. Say: x = [0,

  • 0

I am trying to fix how python plots my data. Say:

x = [0, 5, 9, 10, 15]
y = [0, 1, 2, 3, 4]

matplotlib.pyplot.plot(x, y)
matplotlib.pyplot.show()

The x axis’ ticks are plotted in intervals of 5. Is there a way to make it show intervals of 1?

  • 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-12T00:13:43+00:00Added an answer on June 12, 2026 at 12:13 am

    You could explicitly set where you want to tick marks with plt.xticks:

    plt.xticks(np.arange(min(x), max(x)+1, 1.0))
    

    For example,

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = [0,5,9,10,15]
    y = [0,1,2,3,4]
    plt.plot(x,y)
    plt.xticks(np.arange(min(x), max(x)+1, 1.0))
    plt.show()
    

    (np.arange was used rather than Python’s range function just in case min(x) and max(x) are floats instead of ints.)


    The plt.plot (or ax.plot) function will automatically set default x and y limits. If you wish to keep those limits, and just change the stepsize of the tick marks, then you could use ax.get_xlim() to discover what limits Matplotlib has already set.

    start, end = ax.get_xlim()
    ax.xaxis.set_ticks(np.arange(start, end, stepsize))
    

    The default tick formatter should do a decent job rounding the tick values to a sensible number of significant digits. However, if you wish to have more control over the format, you can define your own formatter. For example,

    ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1f'))
    

    Here’s a runnable example:

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.ticker as ticker
    
    x = [0,5,9,10,15]
    y = [0,1,2,3,4]
    fig, ax = plt.subplots()
    ax.plot(x,y)
    start, end = ax.get_xlim()
    ax.xaxis.set_ticks(np.arange(start, end, 0.712123))
    ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1f'))
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning Python - Beautiful Soup by trying to scrape data. I have
Im trying to fix a Python script which takes the posts from a specific
I'm trying to install matplotlib for graphing applications in Python on Mac OS X.
I'm trying to maintain/update/rewrite/fix a bit of Python that looks a bit like this:
I am trying to implement a K-means algorithm in Python (I know there is
I trying to fix a strange bugg. People with IOS 4 can't even start
I've been trying to fix this problems for a few hours already, I cannot
I am trying to fix a regular input box with padding, border, inside a
I've been trying to fix this error: {exception:Persistent class \Class org.myapp.model.Account does not seem
I am trying to fix Microsoft word smart quotes (and other word smart characters)

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.