Is there a way to place custom patterns into selected areas on an imshow graph? To be precise, I need to make it so that, in addition to the numerical-data-carrying colored squares, I also have different patterns in other squares indicate different failure modes for the experiment (and also generate a key explaining the meaning of these different patterns). An example of a pattern that would be useful would be various types of crosshatches. i need to be able to do this without disrupting the main color-numerical data relationship on the graph.
Below is code from my attempt to use what was suggested in the answers. If I comment the error section the imshow shows up fine with white space wherever there is no data from the masking. I am not even attempting to do different kinds of crosshatching for different failure types or deal with cases where either the simulation or the experiment worked but the other didn't yet.
EDIT3: I am receiving error massages from the multiprocessing package about how it 'can't pickle' the object. Due to the program this is a part of it goes through the multiprocessing package. Any way to fix this or do it without add_patches (the plot method suggested below doesn't work, as the plotting happens on a completely different coordinate system and draws connecting lines)?
import numpy as np
import matplotlib.patches as patches
...
grid = np.ma.array(grid, mask=np.isnan(grid))
plot.imshow(grid, interpolation='nearest', aspect='equal', vmax = private.vmax, vmin = private.vmin)
if show_fail and faildat != []:
faildat = faildat[np.lexsort((faildat[:,yind],faildat[:,xind]))]
fails = []
for i in range(len(faildat)):
fails.append((faildat[i,1],faildat[i,0]))
for F in fails:
p = patches.Rectangle(F,1,1,hatch='/',fill=False)
plot.add_patch(p)
plot.minorticks_off()
plot.set_xticks(range(len(placex)))
plot.set_yticks(range(len(placey)))
plot.set_xticklabels(placex)
plot.set_yticklabels(placey, rotation = 0)
plot.colorbar()
plot.show()
ax
as the object that is returned byimshow
, you need to add the patch objects to anaxes
object. – Demetrademetreimporting matplotlib.pyplot as plot
makes your code a little odd to read. – Demetrademetreplot
to be using it as a variable name at all confuses me. – Demetrademetrepickle
andmultiprocessing
come into this? – Demetrademetrepatch
objects appear to pickle fine..p = mpl.patches.Rectangle((1,1),1,1,hatch='/',fill=False); pickle.dumps(p)
does not raise any errors on my system... – Demetrademetre