Re: [Matplotlib-users] imshow for .png- low resultion
Yes the interpolation had to be set to nearest or bicubic or bilinear for it to function properly!! Thanks a lot!! Asma On Thu, Mar 6, 2014 at 4:48 AM, Pierre Haessig wrote: > Le 05/03/2014 22:37, Asma Riyaz a écrit : > > img= mpimg.imread('/home/asmariyaz/Desktop/mytree.png') > phyl_ax.imshow(img,interpolation='nearest') > > Ok, so here you could try replace 'nearest' by 'bilinear' or 'bicubic'. I > believe those are the most common choices for image resampling (because > when you plot an image and then save it, there is a resampling involved). > (http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.imshow for > the other options) > > Of course, it's also worth playing the dpi argument of savefig, as > suggested by Eric. > > best, > Pierre > > > -- > Subversion Kills Productivity. Get off Subversion & Make the Move to > Perforce. > With Perforce, you get hassle-free workflows. Merge that actually works. > Faster operations. Version large binaries. Built-in WAN optimization and > the > freedom to use Git, Perforce or both. Make the move to Perforce. > > http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] imshow for .png- low resultion
Le 05/03/2014 22:37, Asma Riyaz a écrit : > img= mpimg.imread('/home/asmariyaz/Desktop/mytree.png') > phyl_ax.imshow(img,interpolation='nearest') Ok, so here you could try replace 'nearest' by 'bilinear' or 'bicubic'. I believe those are the most common choices for image resampling (because when you plot an image and then save it, there is a resampling involved). (http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.imshow for the other options) Of course, it's also worth playing the dpi argument of savefig, as suggested by Eric. best, Pierre <> signature.asc Description: OpenPGP digital signature -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] imshow for .png- low resultion
On 2014/03/05 11:37 AM, Asma Riyaz wrote: > Sorry I somehow forgot to paste the imshow call to plot the .png > image(pasted the entire code again), I am trying the different > interpolation parameters in the mean time as suggested by Pierre > > data=np.array(full_len) > cmap = mpl.cm.hot > if outlier==0: > threshold=1 > else: > threshold=outlier-0.01 > > fig = plt.figure(figsize=(25,25)) > plt.suptitle(file_handle.replace('.csv',''),fontsize=22) > cmap.set_over('green') > cmap.set_under('grey') > gs=gridspec.GridSpec(1, 2,height_ratios=[1,1,-2,2] > ,width_ratios=[1,1,-2,2]) > gs.tight_layout(fig,) > phyl_ax=plt.subplot(gs[0]) ##,frameon=False)## > ht_ax=plt.subplot(gs[1],sharey=phyl_ax) > ##gs.tight_layout(fig, rect=[1,1,2,2]) > ht_ax.set_xlim(0,35) > ht_ax.set_ylim(0,35) > ##ht_ax.grid(color='white',linestyle='-',linewidth=1) > ##fig.subplots_adjust(hspace=0) > cb_ax,kw =mpl.colorbar.make_axes(ht_ax, shrink=0.65) > > plt.setp(phyl_ax.get_xticklabels(),visible=False) > plt.setp(phyl_ax.get_yticklabels(),visible=False) > plt.setp(ht_ax.get_xticklabels(),visible=True) > plt.setp(ht_ax.get_yticklabels(),visible=True) > plt.setp(phyl_ax.get_xticklines(),visible=False) > plt.setp(phyl_ax.get_yticklines(),visible=False) > plt.setp(ht_ax.get_xticklines(),visible=True) > plt.setp(ht_ax.get_yticklines(),visible=True) > > > img = ht_ax.imshow(data, cmap=cmap, > interpolation='none',vmax=threshold) > cb = mpl.colorbar.ColorbarBase(ax=cb_ax,cmap=cmap, > extend='neither',**kw) > cb.cmap.set_over('green') > ##image_file = > cbook.get_sample_data('/home/asmariyaz/Desktop/mytree.png',asfileobj=False) > ##image = plt.imread(image_file) > img= mpimg.imread('/home/asmariyaz/Desktop/mytree.png') > phyl_ax.imshow(img,interpolation='nearest') > > heatmap_file=fig.savefig('/home/asmariyaz/Desktop/heatmap/'+file_handle+'.pdf',bbox_inches='tight') Try giving savefig a dpi kwarg to increase the resolution with which the image is saved in the pdf? Turn off anti-aliasing when you make the png? Eric -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] imshow for .png- low resultion
Sorry I somehow forgot to paste the imshow call to plot the .png image(pasted the entire code again), I am trying the different interpolation parameters in the mean time as suggested by Pierre data=np.array(full_len) cmap = mpl.cm.hot if outlier==0: threshold=1 else: threshold=outlier-0.01 fig = plt.figure(figsize=(25,25)) plt.suptitle(file_handle.replace('.csv',''),fontsize=22) cmap.set_over('green') cmap.set_under('grey') gs=gridspec.GridSpec(1, 2,height_ratios=[1,1,-2,2] ,width_ratios=[1,1,-2,2]) gs.tight_layout(fig,) phyl_ax=plt.subplot(gs[0]) ##,frameon=False)## ht_ax=plt.subplot(gs[1],sharey=phyl_ax) ##gs.tight_layout(fig, rect=[1,1,2,2]) ht_ax.set_xlim(0,35) ht_ax.set_ylim(0,35) ##ht_ax.grid(color='white',linestyle='-',linewidth=1) ##fig.subplots_adjust(hspace=0) cb_ax,kw =mpl.colorbar.make_axes(ht_ax, shrink=0.65) plt.setp(phyl_ax.get_xticklabels(),visible=False) plt.setp(phyl_ax.get_yticklabels(),visible=False) plt.setp(ht_ax.get_xticklabels(),visible=True) plt.setp(ht_ax.get_yticklabels(),visible=True) plt.setp(phyl_ax.get_xticklines(),visible=False) plt.setp(phyl_ax.get_yticklines(),visible=False) plt.setp(ht_ax.get_xticklines(),visible=True) plt.setp(ht_ax.get_yticklines(),visible=True) img = ht_ax.imshow(data, cmap=cmap, interpolation='none',vmax=threshold) cb = mpl.colorbar.ColorbarBase(ax=cb_ax,cmap=cmap, extend='neither',**kw) cb.cmap.set_over('green') ##image_file = cbook.get_sample_data('/home/asmariyaz/Desktop/mytree.png',asfileobj=False) ##image = plt.imread(image_file) img= mpimg.imread('/home/asmariyaz/Desktop/mytree.png') phyl_ax.imshow(img,interpolation='nearest') heatmap_file=fig.savefig('/home/asmariyaz/Desktop/heatmap/'+file_handle+'.pdf',bbox_inches='tight') On Wed, Mar 5, 2014 at 3:27 PM, Pierre Haessig wrote: > Hi Asma, > Le 05/03/2014 21:19, Asma Riyaz a écrit : > > I am trying to merge a heat map(matplotlib) with a tree(.png), but the > .png does not plot as needed or for that matter cannot be seen easily. Here > is my code: > > ### CODE > [] > >img = ht_ax.imshow(data, cmap=cmap, interpolation='none',vmax=threshold) >[] > > How can I make the resolution of the .png image better OR for that > matter is there a better solution to merge these together? > > I see the imshow call to plot the matrix but not the one you use to > plot the png image. Could it be that the poor image rendering is due to a > bad choice for the interpolation param ? > > best, > Pierre > > > -- > Subversion Kills Productivity. Get off Subversion & Make the Move to > Perforce. > With Perforce, you get hassle-free workflows. Merge that actually works. > Faster operations. Version large binaries. Built-in WAN optimization and > the > freedom to use Git, Perforce or both. Make the move to Perforce. > > http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] imshow for .png- low resultion
Hi Asma, Le 05/03/2014 21:19, Asma Riyaz a écrit : I am trying to merge a heat map(matplotlib) with a tree(.png), but the .png does not plot as needed or for that matter cannot be seen easily. Here is my code: ### CODE [] img = ht_ax.imshow(data, cmap=cmap, interpolation='none',vmax=threshold) [] How can I make the resolution of the .png image better OR for that matter is there a better solution to merge these together? I see the imshow call to plot the matrix but not the one you use to plot the png image. Could it be that the poor image rendering is due to a bad choice for the interpolation param ? best, Pierre -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] imshow for .png- low resultion
Thank you for replying!! The tree I generate is not based on clustering of matrices but rather on sequence data and hence the tree generation is different in this case. I am still looking into the seaborn project if it can lead me anywhere. Thanks Asma On Wed, Mar 5, 2014 at 3:34 PM, Paul Hobson wrote: > Olga Botnivik is doing some work with these types of figures in her fork > of the seaborn project. > Example here: http://nbviewer.ipython.org/gist/olgabot/8341784 > Link to the PR in github: https://github.com/mwaskom/seaborn/pull/73 > > Those might be a good place to start. > > > > On Wed, Mar 5, 2014 at 12:19 PM, Asma Riyaz wrote: > >> Hi >> I am trying to merge a heat map(matplotlib) with a tree(.png), but the >> .png does not plot as needed or for that matter cannot be seen easily. Here >> is my code: >> >> ### CODE >> cmap = mpl.cm.hot >> if outlier==0: >>threshold=1 >> else: >>threshold=outlier-0.01 >> >> fig = plt.figure(figsize=(25,25)) >> plt.suptitle(file_handle.replace('.csv',''),fontsize=22) >> cmap.set_over('green') >> cmap.set_under('grey') >> gs=gridspec.GridSpec(1, 2,height_ratios=[1,1,-2,2] >> ,width_ratios=[1,1,-2,2]) >> phyl_ax=plt.subplot(gs[0],frameon=False) >> ht_ax=plt.subplot(gs[1]) >> ##gs.tight_layout(fig, rect=[1,1,2,2]) >> ht_ax.set_xlim(0,35) >> ht_ax.set_ylim(0,35) >> ##ht_ax.grid(color='white',linestyle='-',linewidth=1) >> fig.subplots_adjust(hspace=0) >> cb_ax,kw =mpl.colorbar.make_axes(ht_ax, shrink=0.65) >> >> >> plt.setp(phyl_ax.get_xticklabels(),visible=False) >> plt.setp(phyl_ax.get_yticklabels(),visible=False) >> plt.setp(ht_ax.get_xticklabels(),visible=True) >> plt.setp(ht_ax.get_yticklabels(),visible=True) >> plt.setp(phyl_ax.get_xticklines(),visible=False) >> plt.setp(phyl_ax.get_yticklines(),visible=False) >> plt.setp(ht_ax.get_xticklines(),visible=True) >> plt.setp(ht_ax.get_yticklines(),visible=True) >> >> >> img = ht_ax.imshow(data, cmap=cmap, >> interpolation='none',vmax=threshold) >> cb = mpl.colorbar.ColorbarBase(ax=cb_ax,cmap=cmap, >> extend='neither',**kw) >> cb.cmap.set_over('green') >> image_file = >> cbook.get_sample_data('/home/asmariyaz/Desktop/mytree.png',asfileobj=False) >> image = plt.imread(image_file) >> >> How can I make the resolution of the .png image better OR for that matter >> is there a better solution to merge these together? >> >> I am attaching the plot I am getting with this code- (WrongTree.pdf) >> >> Thanks >> Asma >> >> >> -- >> Subversion Kills Productivity. Get off Subversion & Make the Move to >> Perforce. >> With Perforce, you get hassle-free workflows. Merge that actually works. >> Faster operations. Version large binaries. Built-in WAN optimization and >> the >> freedom to use Git, Perforce or both. Make the move to Perforce. >> >> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> > -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] imshow for .png- low resultion
Olga Botnivik is doing some work with these types of figures in her fork of the seaborn project. Example here: http://nbviewer.ipython.org/gist/olgabot/8341784 Link to the PR in github: https://github.com/mwaskom/seaborn/pull/73 Those might be a good place to start. On Wed, Mar 5, 2014 at 12:19 PM, Asma Riyaz wrote: > Hi > I am trying to merge a heat map(matplotlib) with a tree(.png), but the > .png does not plot as needed or for that matter cannot be seen easily. Here > is my code: > > ### CODE > cmap = mpl.cm.hot > if outlier==0: >threshold=1 > else: >threshold=outlier-0.01 > > fig = plt.figure(figsize=(25,25)) > plt.suptitle(file_handle.replace('.csv',''),fontsize=22) > cmap.set_over('green') > cmap.set_under('grey') > gs=gridspec.GridSpec(1, 2,height_ratios=[1,1,-2,2] > ,width_ratios=[1,1,-2,2]) > phyl_ax=plt.subplot(gs[0],frameon=False) > ht_ax=plt.subplot(gs[1]) > ##gs.tight_layout(fig, rect=[1,1,2,2]) > ht_ax.set_xlim(0,35) > ht_ax.set_ylim(0,35) > ##ht_ax.grid(color='white',linestyle='-',linewidth=1) > fig.subplots_adjust(hspace=0) > cb_ax,kw =mpl.colorbar.make_axes(ht_ax, shrink=0.65) > > > plt.setp(phyl_ax.get_xticklabels(),visible=False) > plt.setp(phyl_ax.get_yticklabels(),visible=False) > plt.setp(ht_ax.get_xticklabels(),visible=True) > plt.setp(ht_ax.get_yticklabels(),visible=True) > plt.setp(phyl_ax.get_xticklines(),visible=False) > plt.setp(phyl_ax.get_yticklines(),visible=False) > plt.setp(ht_ax.get_xticklines(),visible=True) > plt.setp(ht_ax.get_yticklines(),visible=True) > > > img = ht_ax.imshow(data, cmap=cmap, > interpolation='none',vmax=threshold) > cb = mpl.colorbar.ColorbarBase(ax=cb_ax,cmap=cmap, > extend='neither',**kw) > cb.cmap.set_over('green') > image_file = > cbook.get_sample_data('/home/asmariyaz/Desktop/mytree.png',asfileobj=False) > image = plt.imread(image_file) > > How can I make the resolution of the .png image better OR for that matter > is there a better solution to merge these together? > > I am attaching the plot I am getting with this code- (WrongTree.pdf) > > Thanks > Asma > > > -- > Subversion Kills Productivity. Get off Subversion & Make the Move to > Perforce. > With Perforce, you get hassle-free workflows. Merge that actually works. > Faster operations. Version large binaries. Built-in WAN optimization and > the > freedom to use Git, Perforce or both. Make the move to Perforce. > > http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] imshow for .png- low resultion
Hi I am trying to merge a heat map(matplotlib) with a tree(.png), but the .png does not plot as needed or for that matter cannot be seen easily. Here is my code: ### CODE cmap = mpl.cm.hot if outlier==0: threshold=1 else: threshold=outlier-0.01 fig = plt.figure(figsize=(25,25)) plt.suptitle(file_handle.replace('.csv',''),fontsize=22) cmap.set_over('green') cmap.set_under('grey') gs=gridspec.GridSpec(1, 2,height_ratios=[1,1,-2,2] ,width_ratios=[1,1,-2,2]) phyl_ax=plt.subplot(gs[0],frameon=False) ht_ax=plt.subplot(gs[1]) ##gs.tight_layout(fig, rect=[1,1,2,2]) ht_ax.set_xlim(0,35) ht_ax.set_ylim(0,35) ##ht_ax.grid(color='white',linestyle='-',linewidth=1) fig.subplots_adjust(hspace=0) cb_ax,kw =mpl.colorbar.make_axes(ht_ax, shrink=0.65) plt.setp(phyl_ax.get_xticklabels(),visible=False) plt.setp(phyl_ax.get_yticklabels(),visible=False) plt.setp(ht_ax.get_xticklabels(),visible=True) plt.setp(ht_ax.get_yticklabels(),visible=True) plt.setp(phyl_ax.get_xticklines(),visible=False) plt.setp(phyl_ax.get_yticklines(),visible=False) plt.setp(ht_ax.get_xticklines(),visible=True) plt.setp(ht_ax.get_yticklines(),visible=True) img = ht_ax.imshow(data, cmap=cmap, interpolation='none',vmax=threshold) cb = mpl.colorbar.ColorbarBase(ax=cb_ax,cmap=cmap, extend='neither',**kw) cb.cmap.set_over('green') image_file = cbook.get_sample_data('/home/asmariyaz/Desktop/mytree.png',asfileobj=False) image = plt.imread(image_file) How can I make the resolution of the .png image better OR for that matter is there a better solution to merge these together? I am attaching the plot I am getting with this code- (WrongTree.pdf) Thanks Asma WrongTree.pdf Description: Adobe PDF document -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users