Skip to content

Colorbar fill not aligned with containing box #17103

Closed
@brunobeltran

Description

@brunobeltran

Bug report

Bug summary

Definitely a low-priority bug, but at some figure sizes, there seems to be an issue with the colorbar not being drawn at the correct position in some backends (seems like PDF and SVG are affected, but not Agg).

The colorbar "fill" (the actual colored bit) will not line up with the box that contains it (the black marker edge that makes the rectangle that is filled by the color bar, see below). Seems like some sort of rounding issue.

I have a more "dramatic" example, but still need to distill it to a minimum working example, as it is a plot of proprietary data.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.cm

fig, ax = plt.subplots(figsize=(2, 1.5))

plt.plot()

sm = matplotlib.cm.ScalarMappable()
sm.set_array([])
plt.colorbar(sm)

plt.savefig('/home/bbeltr1/Downloads/test.svg')
plt.savefig('/home/bbeltr1/Downloads/test.pdf')
plt.savefig('/home/bbeltr1/Downloads/test.png', dpi=800)

Actual outcome

SVG:
test svg

PDF:
test pdf

PNG:
test

Expected outcome

The PNG output has the expected outcome.

Matplotlib version

  • Operating system: Debian Jessie
  • Matplotlib version: master
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version: 3.7
  • Jupyter version (if applicable):
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions