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

  • Home
  • SEARCH
  • 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 9259937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:46:28+00:00 2026-06-18T12:46:28+00:00

I’m trying to format the yaxis on a matplotlib graph using set_major_formatter. The plot

  • 0

I’m trying to format the yaxis on a matplotlib graph using set_major_formatter. The plot is generated correctly, but the ax.yaxis.set_major_formatter() throws a couple of weird errors.

The formatter:

def mjrFormatter(x):
    return "{0:.0f}%".format(x * 100)

The code that uses the formatter:

 ...
 ax.yaxis.set_major_formatter(mjrFormatter)
 ...

Error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-108-b436fe657a8b> in <module>()
----> 1 plot_func(data = data, figsize=(20,10), fig_title = 'title')

<ipython-input-107-d60ffc010a75> in plot_percent_moc(data, figsize, fig_title)
     16         _ = data2[col].plot()
     17 
---> 18     ax.yaxis.set_major_formatter(mjrFormatter)
     19 
     20     fig.suptitle(fig_title, fontsize = 14)

C:\Python27\lib\site-packages\matplotlib\axis.pyc in set_major_formatter(self, formatter)
   1396         self.isDefault_majfmt = False
   1397         self.major.formatter = formatter
-> 1398         formatter.set_axis(self)
   1399 
   1400     def set_minor_formatter(self, formatter):

AttributeError: 'function' object has no attribute 'set_axis'

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\Python27\lib\site-packages\IPython\zmq\pylab\backend_inline.pyc in show(close)
    100     try:
    101         for figure_manager in Gcf.get_all_fig_managers():
--> 102             send_figure(figure_manager.canvas.figure)
    103     finally:
    104         show._to_draw = []

C:\Python27\lib\site-packages\IPython\zmq\pylab\backend_inline.pyc in send_figure(fig)
    209     """
    210     fmt = InlineBackend.instance().figure_format
--> 211     data = print_figure(fig, fmt)
    212     # print_figure will return None if there's nothing to draw:
    213     if data is None:

C:\Python27\lib\site-packages\IPython\core\pylabtools.pyc in print_figure(fig, fmt)
    102     try:
    103         bytes_io = BytesIO()
--> 104         fig.canvas.print_figure(bytes_io, format=fmt, bbox_inches='tight')
    105         data = bytes_io.getvalue()
    106     finally:

C:\Python27\lib\site-packages\matplotlib\backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2050                     orientation=orientation,
   2051                     dryrun=True,
-> 2052                     **kwargs)
   2053                 renderer = self.figure._cachedRenderer
   2054                 bbox_inches = self.figure.get_tightbbox(renderer)

C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    489 
    490     def print_png(self, filename_or_obj, *args, **kwargs):
--> 491         FigureCanvasAgg.draw(self)
    492         renderer = self.get_renderer()
    493         original_dpi = renderer.dpi

C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.pyc in draw(self)
    437 
    438         try:
--> 439             self.figure.draw(self.renderer)
    440         finally:
    441             RendererAgg.lock.release()

C:\Python27\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52     def draw_wrapper(artist, renderer, *args, **kwargs):
     53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
     55         after(artist, renderer)
     56 

C:\Python27\lib\site-packages\matplotlib\figure.pyc in draw(self, renderer)
    997         dsu.sort(key=itemgetter(0))
    998         for zorder, a, func, args in dsu:
--> 999             func(*args)
   1000 
   1001         renderer.close_group('figure')

C:\Python27\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52     def draw_wrapper(artist, renderer, *args, **kwargs):
     53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
     55         after(artist, renderer)
     56 

C:\Python27\lib\site-packages\matplotlib\axes.pyc in draw(self, renderer, inframe)
   2084 
   2085         for zorder, a in dsu:
-> 2086             a.draw(renderer)
   2087 
   2088         renderer.close_group('axes')

C:\Python27\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52     def draw_wrapper(artist, renderer, *args, **kwargs):
     53         before(artist, renderer)
---> 54         draw(artist, renderer, *args, **kwargs)
     55         after(artist, renderer)
     56 

C:\Python27\lib\site-packages\matplotlib\axis.pyc in draw(self, renderer, *args, **kwargs)
   1046         renderer.open_group(__name__)
   1047 
-> 1048         ticks_to_draw = self._update_ticks(renderer)
   1049         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
   1050                                                                 renderer)

C:\Python27\lib\site-packages\matplotlib\axis.pyc in _update_ticks(self, renderer)
    933 
    934         interval = self.get_view_interval()
--> 935         tick_tups = [t for t in self.iter_ticks()]
    936         if self._smart_bounds:
    937             # handle inverted limits

C:\Python27\lib\site-packages\matplotlib\axis.pyc in iter_ticks(self)
    879         majorLocs = self.major.locator()
    880         majorTicks = self.get_major_ticks(len(majorLocs))
--> 881         self.major.formatter.set_locs(majorLocs)
    882         majorLabels = [self.major.formatter(val, i)
    883                        for i, val in enumerate(majorLocs)]

AttributeError: 'function' object has no attribute 'set_locs'

Am I doing something wrong or is this a bug?

  • 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-18T12:46:30+00:00Added an answer on June 18, 2026 at 12:46 pm

    The error is because set_major_formatter assumes it is getting a Formatter object (doc) so it is blowing up when it tries to do stuff with your function.

    I think you are looking for either FormatStrFormatter or FuncFormatter. (doc)

    def mjrFormatter(x, pos):
        return "{0:.0f}%".format(x * 100)
    
    gca().yaxis.set_major_formatter(mpl.ticker.FuncFormatter(mjrFormatter))
    

    The second argument in the signature is mandatory.

    or (which doesn’t do what you want, but is closely related)

    gca().yaxis.set_major_formatter(mpl.ticker.FormatStrFormatter('%.2f%%'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place

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.