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

The Archive Base Latest Questions

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

I have this code: from pylab import * from mpl_toolkits.axes_grid.anchored_artists import AnchoredText import numpy

  • 0

I have this code:

from pylab import *
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
import numpy as np
import matplotlib.pylab as plt


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

ann = AnchoredText('If you zoom in or out, i stay here\nbut can you update this text?',
                  prop=dict(size=8), frameon=True,
                  loc=2,
                  )
ann.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(ann) 

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = (Z1 - Z2) * 10

plt.contourf(X, Y, Z)

plt.show()

Is there a way to anchor text to be always visible but to also be able to use a set_text method like in text objects to update the containing text?
Here i used AnchoredText which is anchored perfectly but i cannot find a method to change the text it contains.
In AnchoredText Matplotlib documentation i cannot find such a method available.
If it cannot be done with AnchoredText can it be done with a simple text object?

EDIT

I accepted the solution from David Zwicker and here is a working example for anyone in need of it:

from pylab import *
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
import numpy as np
import matplotlib.pylab as plt
import random


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

ann = AnchoredText('If you zoom in or out, i stay here\nbut can you update this text?$4.1f$ km s$^{-1}$',
                  prop=dict(size=15), frameon=True,
                  loc=2,
                  )
ann.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(ann) 

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = (Z1 - Z2) * 10

plt.contourf(X, Y, Z)

a = ["hhhhh", "qqqqq", "aaaaaaa","ttttt","yyyyy","oooooooo"]

def setanntext(self):
         ann.txt.set_text(random.choice(a))
         plt.draw()

buttonax = plt.axes([0.7, 0.05, 0.1, 0.1])
button = Button(buttonax, 'set text',color='0.85', hovercolor='0.95')
button.on_clicked(setanntext)

plt.show()
  • 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-14T11:48:06+00:00Added an answer on June 14, 2026 at 11:48 am

    You can access the attribute txt. You can update the anchored text using

    ann.txt.set_text('new text')
    plt.draw()
    

    The plt.draw() is necessary to update the plot and show the new text.

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

Sidebar

Related Questions

I have this code in my forms.py : from django import forms from formfieldset.forms
i have this code from t he django sample tutorial from django.db import models
I have this code: from AppKit import * def setupWindow(): w = NSWindow.alloc() w.initWithContentRect_styleMask_backing_defer_(
I have this code from win32com.client import Dispatch connection_string = Provider=SQLNCLI;server=%s;initial catalog=%s;user id=%s;password=%s%(server,db_name,user,pwd) dbConn
I have this code: from BeautifulSoup import BeautifulSoup TABLE_CONTENT = [['958','<a id=958F href=javascript:c_row(\'958\') title=go
i have this code from a tutorial: // Do the search and show the
I have this source code from 2001 that I would like to compile. It
I have this code that reads from XML file. It gets five strings (groupId,
Ok i have this piece of code from which i took from W3schools :-
I am using iTextSharp in VB.net. I have this piece of code from java

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.