|
From: Asma R. <asm...@gm...> - 2014-03-02 02:40:40
|
Hi, I am trying to insert a .png image to the right side of the plot and following the code mentioned here:Combine picture and plot with Python Matplotlib<http://stackoverflow.com/questions/3765056/combine-picture-and-plot-with-python-matplotlib> Here is what I have tried: import numpy as npfrom matplotlib.colors import LinearSegmentedColormapimport matplotlib.pyplot as pltimport matplotlib as mplimport matplotlib.cbook as cbookfrom matplotlib._png import read_pngfrom matplotlib.offsetbox import OffsetImage cmap = mpl.cm.hot norm = mpl.colors.Normalize(vmin=-1 * outlier, vmax=outlier) cmap.set_over('green') cmap.set_under('green') cmap.set_bad('green') plt.xlim(0,35) plt.ylim(0,35) fig, ax = plt.subplots() ax.set_aspect('equal') cb_ax=fig.add_axes([0.85, 0.1, 0.03, 0.8]) img = ax.imshow(np.ma.masked_values(data, outlier), cmap=cmap, norm=norm, interpolation='none',vmax=outlier) cb = mpl.colorbar.ColorbarBase(cb_ax, cmap=cmap, norm=norm, extend='both')##axim = plt.subplot2grid(shape, loc, rowspan=1) ## phlo tree image_file = cbook.get_sample_data('mytree.png',asfileobj=False) image = plt.imread(image_file) phyl_ax=fig.add_axes([0.10,0.1, 0.03, 0.8]) phyl_ax.imshow(image,interpolation='nearest') Th heat map would be on the left side and the image of a tree will be inserted on the right side. The above code gives me the required heat map but the image I am trying to add on the right side isn't appearing. Can someone lead me as to how I can go about this? Thanks |