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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:24:50+00:00 2026-06-12T19:24:50+00:00

I am trying to set date tick labels on x axis, only for given

  • 0

I am trying to set date tick labels on x axis, only for given points. For example if I have a list of datetime for values on x axis

x = [ datetime.datetime(..), ... , datetime.datetime()]

I tried with ax.xaxis.set_ticklabels(x).

I want to plot date only for each one of six points present in list but I get this result:

plot

The code I used to get this plot is the following:

# figure's size in inch
fig = Figure(figsize=(8, 8))
# axes' position                                
ax = Axes(fig, [.1, .1, .8, .8])
ax.errorbar(matplotlib.dates.date2num(x), y, yerr=el['e'], fmt=format_string, label=label)

# shrinks current axis to 90%
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.9, box.height])
# puts a legend to the right of the current axis
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
# autoscales axes following data limits
ax.autoscale(tight=False)

dateFmt = matplotlib.dates.DateFormatter('%Y-%m-%d')
ax.xaxis.set_major_formatter(dateFmt)
monthsLoc = matplotlib.dates.MonthLocator()
daysLoc = matplotlib.dates.DayLocator(interval=1)
ax.xaxis.set_major_locator(monthsLoc)
ax.xaxis.set_minor_locator(daysLoc)
fig.autofmt_xdate(bottom=0.18)

# I tried to set tick labels with this but with no results
#ax.xaxis.set_ticklabels(x)
# adds axes to figure
fig.add_axes(ax)
# creates a canvas from figure
canvas = FigureCanvasAgg(fig)
# saves figure to filesystem in png format
canvas.print_figure(settings.MEDIA_ROOT + file_relative_path)

What am I doing wrong?

Thanks

  • 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-12T19:24:52+00:00Added an answer on June 12, 2026 at 7:24 pm

    To set ticks and their labels use:

    x = [ datetime.datetime(..), ... , datetime.datetime()]
    ax.xaxis.set_ticks(x)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to set AlarmManager for Specific date, but it is not
I am trying to set my columns default date time to system datetime. It
Trying to get Oracle to Get a date set it to year only and
When am trying to set default date and default sysdate am getting following errors:
I'm trying to set up a date of birth helper in my Rails app
I`m trying to update time in datetime field as UPDATE table_name SET col_name=to_DATE('04/02/2012 00:12:00','MM/DD/YYYY
I'm trying to set the date of a UIDatePicker but I the month is
I'm trying to set the selected date so that it is always the current
I am trying to set the date to todays date in the rad date
I am trying to set the date format of the date picker element, but

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.