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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:11:48+00:00 2026-06-11T15:11:48+00:00

I am running the following snippet of code in the ipython notebook, using the

  • 0

I am running the following snippet of code in the ipython notebook, using the pandas data analysis library along with matplotlib.pyplot.

titles = {'gradStat_p3': "P3:  Gradiometers", 'magStat_p3': "P3:  Magnetometers",
          'gradStat_mmn': "MMN:  Gradiometers", 'magStat_mmn': "MMN:  Magnetometers"}

scales = {'gradStat': (-2.0 * 1e-22, 3.5 * 1e-22), 'magStat': (-1.6 * 1e-25, 4.5 * 1e-25)}

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(8, 5))
fig.tight_layout()
for c, component in enumerate(('p3', 'mmn')):
    for s, sensor in enumerate(('gradStat', 'magStat')):
        key = sensor + '_' + component
        axes[c, s].set_ylim(scales[sensor])
        agg = aggregated[key]
        # Plot
        agg.plot(ax=axes[c, s], kind='bar', legend=False, title=titles[key])
        axes[c, s].set_xticklabels(agg.index.format(names=False))
        if not c:  # hide the labels
            axes[c, s].xaxis.set_visible(False)

        saveFile = '/tmp/ERF_comparative_barplot.pdf'
        fig.savefig(saveFile)

When the above code is executed, the following (correct) plot is produced in the ipython notebook’s inline graphical output:

Correct format

Note that the x-lables are correctly displayed.

When the image is saved, however, the x-labels are cropped as such:

Erroneous format

I have tried calling fig.savefig(savefile, bbox_inches=0, but to no avail. How can I avoid this cropping?

NOTE: For your convenience, I have pickled the aggregated variable here. This is a dictionary of pandas DataFrame objects and it should be all you need to run the above code and reproduce the bug (assuming you have pandas v.0.8.1 installed).

Thanks very much in advance!

  • 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-11T15:11:49+00:00Added an answer on June 11, 2026 at 3:11 pm

    You can use fig.tight_layout().

    fig, ax = subplots(1,1,1)
    ax.plot(np.random.randn(5))
    ax.set_xticklabels(['this is a very long label', 'b', 'c', 'd', 'e'], rotation=90)
    fig.tight_layout()
    fig.savefig('test.pdf')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems running the following code snippet using JavaScript and JQuery. listOfDisplayCategories is
I am running following code to create bmp image from pdf using Ghost4j i
I am using the following code snippet to load a javascript asynchronously, in a
I'm using the following code snippet to determine what process ID my vbscript is
I have the following code snippet to update firefox extension sqlite data base NSString
I'm running the following snippet of code (in ViewDidLoad method of a UITableViewController) to
I'm getting unexpected output when running following code, DateFormat df = new SimpleDateFormat(YYYY-MM-dd); Date
Consider the following snippet running in an applet insdie a browser: WebServiceClient s =
In the following code snippet, Foo1 is a class that increments a counter every
The following code snippet is taken page 112 of the book by Francesco Cesarini

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.