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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:15:43+00:00 2026-06-06T12:15:43+00:00

I want to make some modifications to a few selected tick labels in a

  • 0

I want to make some modifications to a few selected tick labels in a plot.

For example, if I do:

label = axes.yaxis.get_major_ticks()[2].label
label.set_fontsize(size)
label.set_rotation('vertical')

the font size and the orientation of the tick label is changed.

However, if try:

label.set_text('Foo')

the tick label is not modified. Also if I do:

print label.get_text()

nothing is printed.

Here’s some more strangeness. When I tried this:

import matplotlib.pyplot as plt
import numpy as np

axes = plt.figure().add_subplot(111)
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
axes.plot(t, s)
for ticklabel in axes.get_xticklabels():
    print(ticklabel.get_text())

Only empty strings are printed, but the plot contains ticks labeled as ‘0.0’, ‘0.5’, ‘1.0’, ‘1.5’, and ‘2.0’.

enter image description here

  • 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-06T12:15:45+00:00Added an answer on June 6, 2026 at 12:15 pm

    Caveat: Unless the ticklabels are already set to a string (as is usually the case in e.g. a boxplot), this will not work with any version of matplotlib newer than 1.1.0. If you’re working from the current github master, this won’t work. I’m not sure what the problem is yet… It may be an unintended change, or it may not be…

    Normally, you’d do something along these lines:

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots()
    
    # We need to draw the canvas, otherwise the labels won't be positioned and 
    # won't have values yet.
    fig.canvas.draw()
    
    labels = [item.get_text() for item in ax.get_xticklabels()]
    labels[1] = 'Testing'
    
    ax.set_xticklabels(labels)
    
    plt.show()
    

    enter image description here

    To understand the reason why you need to jump through so many hoops, you need to understand a bit more about how matplotlib is structured.

    Matplotlib deliberately avoids doing “static” positioning of ticks, etc, unless it’s explicitly told to. The assumption is that you’ll want to interact with the plot, and so the bounds of the plot, ticks, ticklabels, etc will be dynamically changing.

    Therefore, you can’t just set the text of a given tick label. By default, it’s re-set by the axis’s Locator and Formatter every time the plot is drawn.

    However, if the Locators and Formatters are set to be static (FixedLocator and FixedFormatter, respectively), then the tick labels stay the same.

    This is what set_*ticklabels or ax.*axis.set_ticklabels does.

    Hopefully that makes it slighly more clear as to why changing an individual tick label is a bit convoluted.

    Often, what you actually want to do is just annotate a certain position. In that case, look into annotate, instead.

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

Sidebar

Related Questions

Suppose I want to make an Android device with some custom OS modifications. How
Let's say I want make some of my sources publicly available via my blog
I want to make some clicks with Jquery dynamically onLoad of a page. I
I want to make some design tweaks. Here is the code for html: <div
I want to make some C++ program and I'm using function popen here to
I want to make some changes to the stock Mms Android application and install
I want to make some GUI mockup program for video player, so my idea
i have been programing in vc++ for sometime and i want to make some
I want the user to be able to make some preferences like colors, prefered
I am trying to make some project in which i want a text box

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.