[yt-users] Phase plot pixel has white outline

Matthew Turk matthewturk at gmail.com
Wed Apr 2 14:25:58 PDT 2014


Hi Geoffrey,

On Wed, Apr 2, 2014 at 5:21 PM, Geoffrey So <gsiisg at gmail.com> wrote:
> Hi Matt,
>
> I tried different ways of getting the rasterized kwarg in PhasePlot but
> failed.  I went back to using BinnedProfile2D and got what I wanted, except
> for a minor bug.
>
> When I'm using the following script, the bottom bin fits right into the
> plotting window nicely, but the top of the plotting area always has one
> extra bin of white space compared to PhasePlot's results.  Is there a bug so
> the data and the plotting window doesn't align correctly at the top?

Yes -- if you look at what you're calling, it's "imshow", which
displays it like a bitmap.  What yt will do is use pcolormesh, which
actually requires bin edges, so that will give you a better looking
image in that case.

I think you will be able to get rasterized in as a keyword argument if
you *manually* save your PhasePlot, similar to how the cookbook
examples plot things by grabbing the axes/figure objects on plots.

-Matt

>
> If there's a way to make PhasePlot without the white lines between pixel or
> make this script create perfectly binned bins like PhasePlot then everything
> will be perfect for me.
>
> From
> G.S.
>
> #----------------
> from yt.mods import *
> from matplotlib import *
>
> i=1200
> file='HD%04i' % i
> pf=load(file+'/'+file)
> dd=pf.h.all_data()
>
> z = pf["CosmologyCurrentRedshift"]
> res = pf["TopGridDimensions"][0]
>
> def _HIFraction(field, data):
>    return data["HI_Density"]/(data["HI_Density"]+data["HII_Density"])
>
> add_field("HIFraction", function=_HIFraction, \
>           units=r"\rho_\mathrm{HI}/\rho_\mathrm{H}")
>
> nbins=128
> fieldx='Density'
> fieldy='HIFraction'
> fieldc='CellVolumeCode'
> xmin,xmax = dd.quantities['Extrema'](fieldx, non_zero=True)[0]
> ymin,ymax = dd.quantities['Extrema'](fieldy, non_zero=True)[0]
>
> pro = BinnedProfile2D(data_source=dd,
>     x_n_bins=nbins, x_bin_field=fieldx,
>     x_lower_bound=xmin, x_upper_bound=xmax, x_log=True,
>     y_n_bins=nbins, y_bin_field=fieldy,
>     y_lower_bound=ymin, y_upper_bound=ymax, y_log=True,
>     lazy_reader=True, end_collect=True)
>
> pro.add_fields(fieldc, weight=None)
> extent = ([pro[fieldx][0], pro[fieldx][-1],pro[fieldy][0], pro[fieldy][-1]])
> M=(pro[fieldc].transpose())
> pylab.imshow(M, extent=extent, interpolation='nearest',
>              origin='lower',aspect='auto',norm=colors.LogNorm())
> pylab.yscale('log')
> pylab.xscale('log')
> pylab.ylabel(fieldy +
>              " [$"+pf.field_info[fieldy].get_units()+"$]")
> pylab.xlabel(fieldx +
>              " [$"+pf.field_info[fieldx].get_units()+"$] (z=%2.2f)"
>              % z, labelpad=0)
>
> cb=pylab.colorbar()
> cb.set_label(fieldc +
>              " [$"+pf.field_info[fieldc].get_units()+"$]")
> pylab.savefig('frames/'+file+fieldx+fieldy+fieldc+'.eps')
> #-------------------
>
>
> On Tue, Apr 1, 2014 at 11:27 AM, Matthew Turk <matthewturk at gmail.com> wrote:
>>
>> Hi Geoffrey,
>>
>> I think the solution is in the rasterize=True argument to saving out
>> the figure, which needs to be fed in at the matplotlib level.
>>
>> -Matt
>>
>> On Tue, Apr 1, 2014 at 2:24 PM, Geoffrey So <gsiisg at gmail.com> wrote:
>> > Hi all,
>> >
>> > Is it possible when saving phase plots in EPS format to get rid of the
>> > white
>> > outline of each pixel?  When shrinking the diagram the white makes the
>> > colors look faded.
>> >
>> > From
>> > G.S.
>> >
>> > _______________________________________________
>> > yt-users mailing list
>> > yt-users at lists.spacepope.org
>> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>> >
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>



More information about the yt-users mailing list