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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:22:54+00:00 2026-06-04T04:22:54+00:00

There’s a similar question – but I can’t make the solution proposed there work.

  • 0

There’s a similar question – but I can’t make the solution proposed there work.

Here’s an example plot with a long title:

#!/usr/bin/env python

import matplotlib
import matplotlib.pyplot
import textwrap

x = [1,2,3]
y = [4,5,6]

# initialization:
fig = matplotlib.pyplot.figure(figsize=(8.0, 5.0)) 

# lines:
fig.add_subplot(111).plot(x, y)

# title:
myTitle = "Some really really long long long title I really really need - and just can't - just can't - make it any - simply any - shorter - at all."

fig.add_subplot(111).set_title("\n".join(textwrap.wrap(myTitle, 80)))

# tight:
(matplotlib.pyplot).tight_layout()

# saving:
fig.savefig("fig.png")

it gives a

 AttributeError: 'module' object has no attribute 'tight_layout'

and if I replace (matplotlib.pyplot).tight_layout() with fig.tight_layout() it gives:

 AttributeError: 'Figure' object has no attribute 'tight_layout'

So my question is – how do I fit the title to the plot?

  • 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-04T04:22:54+00:00Added an answer on June 4, 2026 at 4:22 am

    Here’s what I’ve finally used:

    #!/usr/bin/env python3
    
    import matplotlib
    from matplotlib import pyplot as plt
    from textwrap import wrap
    
    data = range(5)
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    ax.plot(data, data)
    
    title = ax.set_title("\n".join(wrap("Some really really long long long title I really really need - and just can't - just can't - make it any - simply any - shorter - at all.", 60)))
    
    fig.tight_layout()
    title.set_y(1.05)
    fig.subplots_adjust(top=0.8)
    
    fig.savefig("1.png")
    

    enter image description here

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

Sidebar

Related Questions

There are nice SO question and answers about this issue, but these options didn't
There was a similar question posted asking in general about alternatives to Qt. Well,
There are plenty of questions and answers to this like this question but I
There's a lot of reading on self referencing problems, but I can't seem to
There are many Subset-sum questions and answers around at SO, but somehow I can't
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There's example: http://www.jquery4u.com/jquery-functions/setinterval-example/#.UHW6_IYY18E Hover over RSS feedburner image - it will shake. In my
There is always some space above my header. How can I remove it? My
There are two tables: aspnet_users and aspnet_membership. Can anyone elaborate on the reasons why
There was a thread on this in comp.lang.javascript recently where victory was announced 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.