Description
Hi again,
In all of the vector graphics backends that I tested (pdf, eps, ps, svg), the colorbar outline is drawn with a broken path at the corner where the path starts and ends. This does not happen with the raster graphic or interactive backends. Here is a minimal working example:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams.update({'axes.linewidth':10})
fig = plt.figure(figsize=(8,6))
ax1 = fig.add_axes([0.05, 0.85, 0.9, 0.1])
ax2 = fig.add_axes([0.05, 0.65, 0.9, 0.1])
ax3 = fig.add_axes([0.05, 0.45, 0.9, 0.1])
ax4 = fig.add_axes([0.05, 0.25, 0.9, 0.1])
ax5 = fig.add_axes([0.05, 0.05, 0.9, 0.1])
cmap = mpl.cm.jet
cmap.set_under('w')
cmap.set_over('w')
im = ax1.pcolormesh(np.linspace(0,10,16).reshape((4,4)))
plt.colorbar(im,cax=ax2,cmap=cmap,orientation='horizontal',
extend='both',extendfrac=0.5)
plt.colorbar(im,cax=ax3,cmap=cmap,orientation='horizontal',
extend='both',)
plt.colorbar(im,cax=ax4,cmap=cmap,orientation='horizontal',
extend='both',extendrect=True)
plt.colorbar(im,cax=ax5,cmap=cmap,orientation='horizontal',
extend='neither')
plt.savefig('colorbar_tip.pdf')
plt.savefig('colorbar_tip.eps')
plt.savefig('colorbar_tip.svg')
Tested with matplotlib 1.4.3, and python 2.7, on Linux and Windows. I have exaggerated the axes linewidth to make the problem more visible. Here is a screenshot of the PDF output:
I have been able to fix this by making the following change to the ColorbarBase
class in colorbar.py:
def _config_axes(self, X, Y):
...
if self.outline is not None:
self.outline.remove()
xy2 = np.append(xy,xy[1:2,:],axis=0) # <-- added
self.outline = mpatches.Polygon(
xy2, edgecolor=mpl.rcParams['axes.edgecolor'], # <-- modified
facecolor='none',
linewidth=mpl.rcParams['axes.linewidth'],
closed=True,
zorder=2)
...
This essentially just copies the second point of the path to the end of the path. However, I don't know if this is the best fix. I don't know anything about vector graphics drawing directives, but it seems to me that there should be a builtin function to have paths wrap-around enough so that it creates a closed loop, including drawing the correct corner. Clearly the closed=True
option of the mpatches.Polygon
is not doing this.
Again, thanks to anyone who looks into this.