I have a colormap on the left of the plot (this was a major problem in itself, it seems only right and top are supported normally) with no borders or ticks.
When this renders it has what looks like a small drop shadow. This appears to be based on the color of the middle of the color bar, and it changes position depending on the thickness of the bar, and appears to become invisible if the bar is more than a few mm thick.
Example code:
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig1 = plt.figure()
ax = fig1.subplots()
#Gradient bar
divider = make_axes_locatable(ax)
cax = divider.append_axes("left", size=0.1, pad=0.5)
X = [[.6, .6], [.7, .7]]
im = cax.imshow(X, interpolation='bicubic', aspect='auto')
cb = fig1.colorbar(im, cax=cax, orientation='vertical')
cb.outline.set_visible(False)
for position, spine in cax.spines.items():
spine.set_visible(False)
cax.get_xaxis().set_ticks([])
cax.get_yaxis().set_ticks([])
plt.tight_layout()
plt.show()
#from io import BytesIO
#f = BytesIO()
#plt.savefig(f, format="svg")
#import xml.etree.cElementTree as ET
#tree, xmlid = ET.XMLID(f.getvalue())
#fn = "DebugTest" + ".svg"
#ET.ElementTree(tree).write(fn)
I have included svg output code because this can be viewed in an image viewer or a browser, which enables you to zoom.
The effect seems to also depend on the resolution and the size of the display window.
Is this some kind of rendering artifact? How can I get rid of it?
In my actual project I am embedding the svgs in html and pdf documents and in those the shadow does not look like a pixel artifact, you can zoom in a long way and it becomes very obvious:
As mentioned in the comments the issues was that the imshow() command was displaying an image which was sometimes not perfectly lined up with the colorbar that was subsequently placed over it. This was copied directly from a stackoverflow answer here: Can I place a vertical colorbar to the left of the plot in matplotlib?
The solutions suggested in the comments are less helpful, but I eventually worked out how to create an image without imshow:
X = [[.6, .6], [.7, .7]]
im = image.AxesImage(None, interpolation='bicubic')
im.set_array(X)
cb = fig1.colorbar(im, cax=cax, orientation='vertical')