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 8060725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:05:14+00:00 2026-06-05T10:05:14+00:00

Matplotlib newbie here. I have the following code: from pylab import figure, show import

  • 0

Matplotlib newbie here.

I have the following code:

from pylab import figure, show
import numpy

fig = figure()
ax = fig.add_subplot(111)

plot_data=[1.7,1.7,1.7,1.54,1.52]

xdata = range(len(plot_data))

labels = ["2009-June","2009-Dec","2010-June","2010-Dec","2011-June"]

ax.plot(xdata,plot_data,"b-")

ax.set_xticks(range(len(labels)))
ax.set_xticklabels(labels)

ax.set_yticks([1.4,1.6,1.8])

fig.canvas.draw()

show()

When you run that code, the resulting chart has a run-in with the first tick label (2009-June) and the origin. How can I get the graph to move over to make that more readable? I tried to put dummy data in, but then Matplotlib (correctly) treats that as data.

  • 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-05T10:05:16+00:00Added an answer on June 5, 2026 at 10:05 am

    add two limits to the x and y axes to shift the tick labels a bit.

    # grow the y axis down by 0.05
    ax.set_ylim(1.35, 1.8)
    # expand the x axis by 0.5 at two ends
    ax.set_xlim(-0.5, len(labels)-0.5)
    

    the result is

    enter image description here

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

Sidebar

Related Questions

I have a matplotlib horizontal bar drawn as follows: import matplotlib.pyplot as plt from
import matplotlib import matplotlib.pyplot as plt import pylab as PL matplotlib.rcParams['axes.unicode_minus'] = False fig
I am using matplotlib for doing this from mpl_toolkits.mplot3d import Axes3D import numpy as
Being a newbie to using matplotlib ,I was trying out some code ,from examples
I've got a Matplotlib graph with two y axes, created like: ax1 = fig.add_subplot(111)
import pylab # matplotlib x_list = [1,1,1,1,5,4] y_list = [1,2,3,4,5,4] pylab.plot(x_list, y_list, 'bo') pylab.show()
I am using matplotlib and numpy to make a polar plot. Here is some
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D Setting the aspect ratio works for
I have a matplotlib figure inside of a wxmpl panel, and am trying to
I have a matplotlib figure on a canvas on a wxpython panel. My application

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.