Skip to content

Adding colorbars to row subplots doesn't render the main plots when saving to .eps in 1.5.0  #5814

Closed
@jklaise

Description

@jklaise

I upgraded to matplotlib 1.5.0 and ran into a potential bug involving colorbars, subplots and saving to .eps for which the only workaround I found was to downgrade back to 1.4.3 where the problem doesn't exist.

Essentially, the .eps output gets corrupted when multiple subplots in a row array (e.g. 1x2) have colorbars added to them. This results in a blank canvas on the main plots of all heatmaps but the first one in the .eps output, whereas the .pdf output works as intended.

A minimal working example:

import matplotlib.pyplot as plt
import numpy as np

data = np.random.rand(100,100)

fig, ax = plt.subplots(1,2)
p1 = ax[0].pcolormesh(data)
p2 = ax[1].pcolormesh(data)

plt.colorbar(p1,ax=ax[0])
plt.colorbar(p2,ax=ax[1])

fig.savefig('test.pdf')
fig.savefig('test.eps')

These are the outputs (converted to .png, the top line in the .eps output in the second subplot is just an artefact from converting to .png):

.pdf:
alt text

.eps:
alt text

The problem persists when replacing pcolormesh with pcolor or imshow, using cax for colorbar axis instead of ax, changing colormaps, using row arrays of more subplots (for 1xn the last n-1 subplots have empty canvas), using gridspec to define subplots. The only thing that resolved this was to downgrade back to 1.4.3.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions