Skip to content

Saving plot as PNG file prunes tick labels  #12564

Closed

Description

@JackCaster

Bug report

Bug summary
When I export a plot to PNG, some tick labels are pruned. This does not happen if I use another format, such as PDF or SVG.
Code for reproduction
I failed to recreate the problem with a dummy dataset. It seems that the problem is very much an edge case probably. This is what I see on my Jupyter notebook:
image

The plot is exported nicely in PDF: test.pdf

But, if I use PNG, the bottom and upper y-tick labels are pruned:
test

I tried to play around with the padding in plt.tight_layout() and the options in plt.savefig() without success.

Matplotlib version

  • Operating system: Windows 10 Pro N
  • Matplotlib version: 3.0.0 (from Conda)
  • Matplotlib backend: module://ipykernel.pylab.backend_inline
  • Python version: 3.6.6 (from Conda)
  • Jupyter version (if applicable): 1.0.0

Activity

  1. ImportanceOfBeingErnest commented on Oct 19, 2018

    @ImportanceOfBeingErnest
    Member

    Feel free to provide a minimal verifiable example, which allows to reproduce the probem. Else, I see little chance to help here.

  2. jklymak commented on Oct 19, 2018

    @jklymak
    Member

    Try increasing your dpi on the png.

    There is some weird dpi-dependent code for adding or dropping ticks. One of my prs fixes it though I’m not sure if it’s been merged yet. EDIT: Not merged: #12158

  3. JackCaster commented on Oct 19, 2018

    @JackCaster
    Author

    Try increasing your dpi on the png.

    There is some weird dpi-dependent code for adding or dropping ticks. One of my prs fixes it though I’m not sure if it’s been merged yet. EDIT: Not merged: #12158

    It is indeed related to the DPI I set. But it is the other way around you suggested. Up to 80 DPI everything is fine. Above that, the tick labels are pruned. Weird. I would try to come up with a reproducible example.

  4. jklymak commented on Oct 19, 2018

    @jklymak
    Member

    You probably don't need to - its a known issue... From my testing, I think its an issue of your upper ylimit limit being close, but less than, 1.25. When you decrese the dpi, your upper limit becomes within 1/2 a pixel of 1.25 and includes the 1.25; when you increase the dpi your upper limit is no longer within 1/2 a pixel, and it gets trimmed.

    #12158 will always trim that tick because your upper y-limit < 1.25. Of course, if you manually specify set_ylim([0, 1.25]) it will not be trimmed. I think that is the correct and consistent behaviour.

  5. jklymak commented on Oct 19, 2018

    @jklymak
    Member

    A minimal example is:

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots()
    ax.set_ylim(0, 1.199)
    
    fig.savefig('boo100.png', dpi=100)
    fig.savefig('boo200.png', dpi=200)

    boo100

    boo200

  6. JackCaster commented on Oct 21, 2018

    @JackCaster
    Author

    You probably don't need to - its a known issue... From my testing, I think its an issue of your upper ylimit limit being close, but less than, 1.25. When you decrese the dpi, your upper limit becomes within 1/2 a pixel of 1.25 and includes the 1.25; when you increase the dpi your upper limit is no longer within 1/2 a pixel, and it gets trimmed.

    #12158 will always trim that tick because your upper y-limit < 1.25. Of course, if you manually specify set_ylim([0, 1.25]) it will not be trimmed. I think that is the correct and consistent behaviour.

    Thank you. That worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions