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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:44:18+00:00 2026-06-05T21:44:18+00:00

I have an index array (x) of dates (datetime objects) and an array of

  • 0

I have an index array (x) of dates (datetime objects) and an array of actual values (y: bond prices). Doing the following:

plot(x,y)

produces a perfectly fine time series graph with the x-axis labeled with the dates. No problem so far. But I want to add text on certain dates. For example, on 2009-10-31, I wish to display the text "Event 1" with an arrow pointing to the y value at that date.

I have read through the Matplotlib documentation on text() and annotate() to no avail.

  • 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-05T21:44:20+00:00Added an answer on June 5, 2026 at 9:44 pm

    Matplotlib uses an internal floating point format for dates.

    You just need to convert your date to that format (using matplotlib.dates.date2num or matplotlib.dates.datestr2num) and then use annotate as usual.

    As a somewhat excessively fancy example:

    import datetime as dt
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates
    
    x = [dt.datetime(2009, 05, 01), dt.datetime(2010, 06, 01), 
         dt.datetime(2011, 04, 01), dt.datetime(2012, 06, 01)]
    y = [1, 3, 2, 5]
    
    fig, ax = plt.subplots()
    ax.plot_date(x, y, linestyle='--')
    
    ax.annotate('Test', (mdates.date2num(x[1]), y[1]), xytext=(15, 15), 
                textcoords='offset points', arrowprops=dict(arrowstyle='-|>'))
    
    fig.autofmt_xdate()
    plt.show()
    

    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 the following arrays: var dates = new Array(); var answers = new
I have a bit array implementation where the 0th index is the MSB of
I have an array for instance, Array { 3.0 at Index 0 2.0 at
hi i have multidimensional array in php i want to remove an index from
i have this JSON: var projects_array = new Array( {name:myName1, id:myid1, index:1}, {name:myName2, id:myid2,
Is it possible to start an array at an index not zero...I.E. you have
I have an array with dates as indices which I'm plotting. I'd like to
i have a DateTimeArray this array contain DateTimeArray[index 0] = 20.05.2011 12:12:50 DateTimeArray[index 1]=
I have the following HAML written to take the place of a scaffold index
I have the following code in a CakePHP Controller: var $searchCondition = array( 'Item.date

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.