2

I am trying to mask out the bound density of a system with the masking field

@derived_field(name = "bound_density", units = "g/cm**3")
def _get_ejected_density(field, data):
        E = 0.5* data["cell_mass"]* (data["velx"]**2+data["vely"]**2+data["velz"]**2)+ data["gpot"]*data["cell_mass"]
        return ((np.array(E)<0)*1)*data["density"]

It also returns the unbound density with the white color bars along with the bound density, but I don't want to show the unbound things here.

I was wondering if there is a way I can only show the bound material in this plot. Also another solution would be setting the unbound density color bar matching to the floor bar, hence 1.0e0, so that while the plot still shows the unbound density, it exactly matches the lowest density color bar in the plot and thus cannot be distinguished.

enter image description here

bhjghjh
  • 889
  • 3
  • 16
  • 42

1 Answers1

1

Here's an example that shows how to manipulate the colorbar so the background color matches the color at the bottom of the colorbar:

https://gist.github.com/4d07fc6475becd18b793e15ae2f00dff

ngoldbaum
  • 5,430
  • 3
  • 28
  • 35
  • thanks @nathan12343, but I get this AttributeError: 'module' object has no attribute 'viridis', yt and matplotlib are imported. does it need another mudule to import ? – bhjghjh Aug 04 '16 at 00:12
  • Viridis is a new colormap that comes in matplotlib 1.5.0 and newer. You can use any matplotlib colormap you want, although you could also update matplotlib to get viridis. – ngoldbaum Aug 04 '16 at 00:52
  • at this point, I think it would be enough if I just set the background color to be white, I will get rid of unbound material through that, can you show me the code to set background color white for this plot? – bhjghjh Aug 04 '16 at 01:38
  • I'm confused - it's already white in the version of the plot in your question. – ngoldbaum Aug 04 '16 at 01:42
  • The white part in my figure denotes the unbound material, but I don't want to show that, I thought if I could set my figure in a complete white background then the unbound part will blend completely with the background and it will not be prominent anymore – bhjghjh Aug 04 '16 at 01:47
  • I still think the easiest way to do this is to pick a background color that matches the bottom color of your colormap. I'll update my answer with something that should work with your version of matplotlib. – ngoldbaum Aug 04 '16 at 01:54