Question about Projection Plot Color Coding

Hello All, I have a question about the Projection plot function in yt. I have a script that plots the smallest mass darkmatter particles of a simulation in all 3 of the 2-d coordinate projections, and overplots the halos found by a halo finder. This script works, and currently plots the colorbar based on the mass in a given 2-d bin as done in some of the basic yt plots included in the website. I am wondering if it is possible to have the color scheme of the particles be based on the squared mass or squared density of the particles in any given 2-d bin, so that the higher density regions are highlighted compared to the background lower density regions. I have included the plotting part of my script below, in case it is helpful. I hope everyone is having a great New Year! ds = yt.load(VELA_snaps[position[0]]) domain_width = float(ds.domain_width.in_units('Mpc/h')[0]) ad = ds.all_data() masses = yt.np.unique(ad[('darkmatter', 'particle_mass')]) #filter out the darkmatter0 particles def mass_filter(pfilter, data): filter = data[(pfilter.filtered_type, 'particle_mass')] == masses[0] return filter yt.add_particle_filter('darkmatter0', function=mass_filter, filtered_type='darkmatter', requires=['particle_mass']) ds.add_particle_filter('darkmatter0') scale = float(ds.scale_factor) fig = plt.figure() grid = AxesGrid(fig, (0.075,0.075,10,5), nrows_ncols = (3, 1), axes_pad = 1.0, label_mode = "L", share_all = False, cbar_location="right", cbar_mode="each", cbar_size="3%", cbar_pad="0%") zoom = 10 x0 = float(consistent.halo_data_sorted[index][0][17]) * scale / domain_width y0 = float(consistent.halo_data_sorted[index][0][18]) * scale / domain_width z0 = float(consistent.halo_data_sorted[index][0][19]) * scale / domain_width center = [x0, y0, z0] a = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_x'), ('darkmatter0', 'particle_position_y'),\ ('darkmatter0', 'particle_mass'), center=center) a.set_unit(('darkmatter0','particle_mass'), 'Msun') a.zoom(zoom) b = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_y'), ('darkmatter0', 'particle_position_z'),\ ('darkmatter0', 'particle_mass'), center=center) b.set_unit(('darkmatter0','particle_mass'), 'Msun') b.zoom(zoom) c = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_z'), ('darkmatter0', 'particle_position_x'),\ ('darkmatter0', 'particle_mass'), center=center) c.set_unit(('darkmatter0','particle_mass'), 'Msun') c.zoom(zoom) for halos in consistent.halo_data_sorted[index]: x = float(halos[17]) * scale / domain_width y = float(halos[18]) * scale / domain_width z = float(halos[19]) * scale / domain_width r = float(halos[11]) * scale / .7 center = [x, y, z] a.annotate_sphere(center, radius=(r, 'kpc'), circle_args={'color':'red'}) b.annotate_sphere(center, radius=(r, 'kpc'), circle_args={'color':'red'}) c.annotate_sphere(center, radius=(r, 'kpc'), circle_args={'color':'red'}) index = 0 for letter in [a,b,c]: plot = letter.plots[('darkmatter0', 'particle_mass')] plot.figure = fig plot.axes = grid[index].axes plot.cax = grid.cbar_axes[index] letter._setup_plots() index = index + 1 plt.savefig('{}/CatalogProjectionYT_VELA{}_Scale{}.png'.format(out_dir, VELA_number, str(scale)[2:5]), bbox_inches='tight') plt.close()

Hi Sean, I've been trying to think of the easiest way to do this in the framework you suggest, and I have a few ideas. The simplest way would likely be to use a different matplotlib normalizer for your particle colors: https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.colors.Normalize.html Since you're already accessing the plot.cax objects, you should be able to swap it there. You should then be able to avoid doing anything with derived fields, etc, as you could control the color maps themselves. Do you think that could be a workable solution? -Matt On Thu, Jan 2, 2020 at 5:52 PM Sean Larkin via yt-users <yt-users@python.org> wrote:
Hello All,
I have a question about the Projection plot function in yt. I have a script that plots the smallest mass darkmatter particles of a simulation in all 3 of the 2-d coordinate projections, and overplots the halos found by a halo finder. This script works, and currently plots the colorbar based on the mass in a given 2-d bin as done in some of the basic yt plots included in the website. I am wondering if it is possible to have the color scheme of the particles be based on the squared mass or squared density of the particles in any given 2-d bin, so that the higher density regions are highlighted compared to the background lower density regions. I have included the plotting part of my script below, in case it is helpful.
I hope everyone is having a great New Year!
ds = yt.load(VELA_snaps[position[0]]) domain_width = float(ds.domain_width.in_units('Mpc/h')[0]) ad = ds.all_data() masses = yt.np.unique(ad[('darkmatter', 'particle_mass')]) #filter out the darkmatter0 particles def mass_filter(pfilter, data): filter = data[(pfilter.filtered_type, 'particle_mass')] == masses[0] return filter yt.add_particle_filter('darkmatter0', function=mass_filter, filtered_type='darkmatter', requires=['particle_mass']) ds.add_particle_filter('darkmatter0')
scale = float(ds.scale_factor)
fig = plt.figure()
grid = AxesGrid(fig, (0.075,0.075,10,5), nrows_ncols = (3, 1), axes_pad = 1.0, label_mode = "L", share_all = False, cbar_location="right", cbar_mode="each", cbar_size="3%", cbar_pad="0%")
zoom = 10
x0 = float(consistent.halo_data_sorted[index][0][17]) * scale / domain_width y0 = float(consistent.halo_data_sorted[index][0][18]) * scale / domain_width z0 = float(consistent.halo_data_sorted[index][0][19]) * scale / domain_width center = [x0, y0, z0]
a = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_x'), ('darkmatter0', 'particle_position_y'),\ ('darkmatter0', 'particle_mass'), center=center) a.set_unit(('darkmatter0','particle_mass'), 'Msun') a.zoom(zoom) b = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_y'), ('darkmatter0', 'particle_position_z'),\ ('darkmatter0', 'particle_mass'), center=center) b.set_unit(('darkmatter0','particle_mass'), 'Msun') b.zoom(zoom) c = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_z'), ('darkmatter0', 'particle_position_x'),\ ('darkmatter0', 'particle_mass'), center=center) c.set_unit(('darkmatter0','particle_mass'), 'Msun') c.zoom(zoom)
for halos in consistent.halo_data_sorted[index]: x = float(halos[17]) * scale / domain_width y = float(halos[18]) * scale / domain_width z = float(halos[19]) * scale / domain_width r = float(halos[11]) * scale / .7 center = [x, y, z] a.annotate_sphere(center, radius=(r, 'kpc'), circle_args={'color':'red'}) b.annotate_sphere(center, radius=(r, 'kpc'), circle_args={'color':'red'}) c.annotate_sphere(center, radius=(r, 'kpc'), circle_args={'color':'red'})
index = 0 for letter in [a,b,c]: plot = letter.plots[('darkmatter0', 'particle_mass')] plot.figure = fig plot.axes = grid[index].axes plot.cax = grid.cbar_axes[index] letter._setup_plots() index = index + 1
plt.savefig('{}/CatalogProjectionYT_VELA{}_Scale{}.png'.format(out_dir, VELA_number, str(scale)[2:5]), bbox_inches='tight') plt.close() _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org

Hello Matt, Sorry for the dredging up a question from quite a bit ago. I had completely forgotten that I wanted to do this until reminded by the person who initially requested I make these plots. As far as your recommendation, I do think that should be a workable solution, but I am running into an issue. Currently, I am attempting to just implement the log scaling shown in the example page you linked, and have a question about its interface with the yt-projection plot. I will include my modified code to illustrate my question/issue. index = 0 for letter in [a,b,c]: plot = letter.plots[('darkmatter0', 'particle_mass')] plot.figure = fig plot.axes = grid[index].axes plot.cax = grid.cbar_axes[index]#.colorbar(pcm, ax=grid[index].axes) pcm = grid.cbar_axes[index].pcolor(x, y, z, norm=colors.LogNorm(vmin=z.min(), vmax=z.max())) fig.colorbar(pcm, ax=ax[index]) letter._setup_plots() index = index + 1 For the .pcolor call to modify the norm, it requires an x, y, z inputs, for the x and y axis of the plot (the x-y projections of space from the projectionplot), with the z being the colorbar paramater (particle_mass for this case). As the data is coming from yt.projectionplots, I am not sure where/what the proper inputs for these fields are. I have done some looking around, but am unsure what these should be. Do you have any insight into where these fields are stored/can be accessed to be re passed to this call? On Fri, Jan 3, 2020 at 6:19 AM Matthew Turk <matthewturk@gmail.com> wrote:
Hi Sean,
I've been trying to think of the easiest way to do this in the framework you suggest, and I have a few ideas. The simplest way would likely be to use a different matplotlib normalizer for your particle colors:
https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.colors.Normalize.html
Since you're already accessing the plot.cax objects, you should be able to swap it there. You should then be able to avoid doing anything with derived fields, etc, as you could control the color maps themselves.
Do you think that could be a workable solution?
-Matt
On Thu, Jan 2, 2020 at 5:52 PM Sean Larkin via yt-users <yt-users@python.org> wrote:
Hello All,
I have a question about the Projection plot function in yt. I have a
script that plots the smallest mass darkmatter particles of a simulation in all 3 of the 2-d coordinate projections, and overplots the halos found by a halo finder. This script works, and currently plots the colorbar based on the mass in a given 2-d bin as done in some of the basic yt plots included in the website. I am wondering if it is possible to have the color scheme of the particles be based on the squared mass or squared density of the particles in any given 2-d bin, so that the higher density regions are highlighted compared to the background lower density regions. I have included the plotting part of my script below, in case it is helpful.
I hope everyone is having a great New Year!
ds = yt.load(VELA_snaps[position[0]]) domain_width = float(ds.domain_width.in_units('Mpc/h')[0]) ad = ds.all_data() masses = yt.np.unique(ad[('darkmatter', 'particle_mass')]) #filter out the darkmatter0 particles def mass_filter(pfilter, data): filter = data[(pfilter.filtered_type, 'particle_mass')] ==
masses[0]
return filter yt.add_particle_filter('darkmatter0', function=mass_filter,
filtered_type='darkmatter', requires=['particle_mass'])
ds.add_particle_filter('darkmatter0')
scale = float(ds.scale_factor)
fig = plt.figure()
grid = AxesGrid(fig, (0.075,0.075,10,5), nrows_ncols = (3, 1), axes_pad = 1.0, label_mode = "L", share_all = False, cbar_location="right", cbar_mode="each", cbar_size="3%", cbar_pad="0%")
zoom = 10
x0 = float(consistent.halo_data_sorted[index][0][17]) * scale /
domain_width
y0 = float(consistent.halo_data_sorted[index][0][18]) * scale /
domain_width
z0 = float(consistent.halo_data_sorted[index][0][19]) * scale /
domain_width
center = [x0, y0, z0]
a = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_x'),
('darkmatter0', 'particle_position_y'),\
('darkmatter0', 'particle_mass'),
center=center)
a.set_unit(('darkmatter0','particle_mass'), 'Msun') a.zoom(zoom) b = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_y'),
('darkmatter0', 'particle_position_z'),\
('darkmatter0', 'particle_mass'),
center=center)
b.set_unit(('darkmatter0','particle_mass'), 'Msun') b.zoom(zoom) c = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_z'),
('darkmatter0', 'particle_position_x'),\
('darkmatter0', 'particle_mass'),
center=center)
c.set_unit(('darkmatter0','particle_mass'), 'Msun') c.zoom(zoom)
for halos in consistent.halo_data_sorted[index]: x = float(halos[17]) * scale / domain_width y = float(halos[18]) * scale / domain_width z = float(halos[19]) * scale / domain_width r = float(halos[11]) * scale / .7 center = [x, y, z] a.annotate_sphere(center, radius=(r, 'kpc'),
circle_args={'color':'red'})
b.annotate_sphere(center, radius=(r, 'kpc'),
circle_args={'color':'red'})
c.annotate_sphere(center, radius=(r, 'kpc'),
circle_args={'color':'red'})
index = 0 for letter in [a,b,c]: plot = letter.plots[('darkmatter0', 'particle_mass')] plot.figure = fig plot.axes = grid[index].axes plot.cax = grid.cbar_axes[index] letter._setup_plots() index = index + 1
plt.savefig('{}/CatalogProjectionYT_VELA{}_Scale{}.png'.format(out_dir, VELA_number, str(scale)[2:5]), bbox_inches='tight')
plt.close() _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org

Hi Sean, Hmm, interesting point. OK, so in all honest I usually use imshow, but to use pcolor to supply the x y you'll need to specify what they are. You can likely do this by doing some form of np.mgrid or np.linspace from one extent to the other. The reason pcolor allows this (and pcolormesh as well, which may be faster) is that you can have variably sized bins. With imshow you can just specify the extent. On Wed, Jul 8, 2020 at 11:54 PM Sean Larkin <seanfrancislarkin@gmail.com> wrote:
Hello Matt,
Sorry for the dredging up a question from quite a bit ago. I had completely forgotten that I wanted to do this until reminded by the person who initially requested I make these plots.
As far as your recommendation, I do think that should be a workable solution, but I am running into an issue. Currently, I am attempting to just implement the log scaling shown in the example page you linked, and have a question about its interface with the yt-projection plot. I will include my modified code to illustrate my question/issue.
index = 0 for letter in [a,b,c]: plot = letter.plots[('darkmatter0', 'particle_mass')] plot.figure = fig plot.axes = grid[index].axes plot.cax = grid.cbar_axes[index]#.colorbar(pcm, ax=grid[index].axes)
pcm = grid.cbar_axes[index].pcolor(x, y, z, norm=colors.LogNorm(vmin=z.min(), vmax=z.max()))
fig.colorbar(pcm, ax=ax[index]) letter._setup_plots() index = index + 1
For the .pcolor call to modify the norm, it requires an x, y, z inputs, for the x and y axis of the plot (the x-y projections of space from the projectionplot), with the z being the colorbar paramater (particle_mass for this case). As the data is coming from yt.projectionplots, I am not sure where/what the proper inputs for these fields are. I have done some looking around, but am unsure what these should be. Do you have any insight into where these fields are stored/can be accessed to be re passed to this call?
On Fri, Jan 3, 2020 at 6:19 AM Matthew Turk <matthewturk@gmail.com> wrote:
Hi Sean,
I've been trying to think of the easiest way to do this in the framework you suggest, and I have a few ideas. The simplest way would likely be to use a different matplotlib normalizer for your particle colors:
https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.colors.Normalize.html
Since you're already accessing the plot.cax objects, you should be able to swap it there. You should then be able to avoid doing anything with derived fields, etc, as you could control the color maps themselves.
Do you think that could be a workable solution?
-Matt
On Thu, Jan 2, 2020 at 5:52 PM Sean Larkin via yt-users <yt-users@python.org> wrote:
Hello All,
I have a question about the Projection plot function in yt. I have a
script that plots the smallest mass darkmatter particles of a simulation in all 3 of the 2-d coordinate projections, and overplots the halos found by a halo finder. This script works, and currently plots the colorbar based on the mass in a given 2-d bin as done in some of the basic yt plots included in the website. I am wondering if it is possible to have the color scheme of the particles be based on the squared mass or squared density of the particles in any given 2-d bin, so that the higher density regions are highlighted compared to the background lower density regions. I have included the plotting part of my script below, in case it is helpful.
I hope everyone is having a great New Year!
ds = yt.load(VELA_snaps[position[0]]) domain_width = float(ds.domain_width.in_units('Mpc/h')[0]) ad = ds.all_data() masses = yt.np.unique(ad[('darkmatter', 'particle_mass')]) #filter out the darkmatter0 particles def mass_filter(pfilter, data): filter = data[(pfilter.filtered_type, 'particle_mass')] ==
masses[0]
return filter yt.add_particle_filter('darkmatter0', function=mass_filter,
filtered_type='darkmatter', requires=['particle_mass'])
ds.add_particle_filter('darkmatter0')
scale = float(ds.scale_factor)
fig = plt.figure()
grid = AxesGrid(fig, (0.075,0.075,10,5), nrows_ncols = (3, 1), axes_pad = 1.0, label_mode = "L", share_all = False, cbar_location="right", cbar_mode="each", cbar_size="3%", cbar_pad="0%")
zoom = 10
x0 = float(consistent.halo_data_sorted[index][0][17]) * scale /
domain_width
y0 = float(consistent.halo_data_sorted[index][0][18]) * scale /
domain_width
z0 = float(consistent.halo_data_sorted[index][0][19]) * scale /
domain_width
center = [x0, y0, z0]
a = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_x'),
('darkmatter0', 'particle_position_y'),\
('darkmatter0', 'particle_mass'),
center=center)
a.set_unit(('darkmatter0','particle_mass'), 'Msun') a.zoom(zoom) b = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_y'),
('darkmatter0', 'particle_position_z'),\
('darkmatter0', 'particle_mass'),
center=center)
b.set_unit(('darkmatter0','particle_mass'), 'Msun') b.zoom(zoom) c = yt.ParticlePlot(ds, ('darkmatter0', 'particle_position_z'),
('darkmatter0', 'particle_position_x'),\
('darkmatter0', 'particle_mass'),
center=center)
c.set_unit(('darkmatter0','particle_mass'), 'Msun') c.zoom(zoom)
for halos in consistent.halo_data_sorted[index]: x = float(halos[17]) * scale / domain_width y = float(halos[18]) * scale / domain_width z = float(halos[19]) * scale / domain_width r = float(halos[11]) * scale / .7 center = [x, y, z] a.annotate_sphere(center, radius=(r, 'kpc'),
circle_args={'color':'red'})
b.annotate_sphere(center, radius=(r, 'kpc'),
circle_args={'color':'red'})
c.annotate_sphere(center, radius=(r, 'kpc'),
circle_args={'color':'red'})
index = 0 for letter in [a,b,c]: plot = letter.plots[('darkmatter0', 'particle_mass')] plot.figure = fig plot.axes = grid[index].axes plot.cax = grid.cbar_axes[index] letter._setup_plots() index = index + 1
plt.savefig('{}/CatalogProjectionYT_VELA{}_Scale{}.png'.format(out_dir, VELA_number, str(scale)[2:5]), bbox_inches='tight')
plt.close() _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
participants (3)
-
Matthew Turk
-
Sean Larkin
-
sflarkin@ucsc.edu