Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

tight_layout reserves tick space even if disabled #11203

Closed
Milestone
@surchs

Description

@surchs

Bug report

tight_layout seems to reserve space for axes ticks even if they are removed

I like to save a plot with zero surrounding whitespace.

Previously (version 1.5.3) this was possible by settingbbox_inches='tight', pad_inches=0 in thesavefig call and removing any axis decorators (ticks, labels). In the current version (version 2.2.2) the whitespace around the plot cannot be fully removed in the above way, even if decorators are removed. It seems that the remaining whitespace corresponds to the area that the axis ticks would be drawn in, had they not been removed.

This seems to be related torecent changes in how axes legends get drawn:

Tools like fig.tight_layout() and fig.savefig(bbox_inches='tight') would clip these legends. A change was made to include them in the tight calculations.

It seems not possible to save a plot with no surrounding whitespace in the current version.

Code for reproduction

importnumpyasnpfrommatplotlibimportpyplotasplt# axis ticks drawnf=plt.figure(figsize=(1,1))ax=f.add_subplot(111)ax.matshow(np.ones((10,10)),cmap=plt.cm.Blues_r,aspect='auto')ax.set_xticklabels([])ax.set_yticklabels([])#ax.axis('off')f.savefig('test_ticks.png',dpi=300,bbox_inches='tight',pad_inches=0,facecolor='red')# axis ticks removedf=plt.figure(figsize=(1,1))ax=f.add_subplot(111)ax.matshow(np.ones((10,10)),cmap=plt.cm.Blues_r,aspect='auto')ax.set_xticklabels([])ax.set_yticklabels([])ax.axis('off')f.savefig('test_noticks.png',dpi=300,bbox_inches='tight',pad_inches=0,facecolor='red')

Actual outcome (using matplotlib 2.2.2)
test_ticks.png:
image
image dimensions: 239 * 232 pixels

test_noticks.png:
image
image dimensions: 239 * 232 pixels

Expected outcome (using matplotlib 1.5.3)
test_ticks.png:
image
image dimensions: 232 * 232 pixels
(drawing the ticks inside the plot is obviously not desirable as well but I think this illustrates the difference in behaviour)

test_noticks.png:
image
image dimensions: 232 * 232 pixels
(this is what I'd like to get with the above code).

Matplotlib version

  • Operating system: Ubuntu 16.04 LTS
  • Matplotlib version: 2.2.2
  • Matplotlib backend (print(matplotlib.get_backend())):module://ipykernel.pylab.backend_inline (also tried in Qt5Agg)
  • Python version: 3.6.5
  • Jupyter version (if applicable): 4.4.0
  • Other libraries:
backcall==0.1.0certifi==2018.4.16cycler==0.10.0Cython==0.28.2decorator==4.3.0ipykernel==4.8.2ipython==6.3.1ipython-genutils==0.2.0jedi==0.12.0jupyter-client==5.2.3jupyter-core==4.4.0kiwisolver==1.0.1matplotlib==2.2.2mkl-fft==1.0.0mkl-random==1.0.1nibabel==2.2.1nilearn==0.4.1numpy==1.14.2olefile==0.45.1parso==0.2.0pexpect==4.5.0pickleshare==0.7.4Pillow==5.1.0prompt-toolkit==1.0.15ptyprocess==0.5.2Pygments==2.2.0pyparsing==2.2.0PyQt5==5.10.1python-dateutil==2.7.2pytz==2018.4pyzmq==17.0.0scikit-learn==0.19.1scipy==1.0.1simplegeneric==0.8.1sip==4.19.8six==1.11.0tornado==5.0.2traitlets==4.3.2wcwidth==0.1.7

All throught conda default channel, the code example was run in two separate virtual environments, one downgraded to matplotlib 1.5.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp