Recent numpy/matplotlib finds: Log plotting and map projections

With a change of research focus comes a change of tools. I’m fiddling with clusters of galaxies at the moment (GR stuff has been put slightly to one side for a little while), so I’ve been re-educating myself in the art of handling catalogues. I discovered a handful of neat numpy/matplotlib routines in the process, which I thought I’d share:

  • Map projections: You can project plots differently by using the projection keyword argument for subplot, e.g. subplot(111, projection="mollweide")
  • Logarithmic sampling: If you need to sample some function on a logarithmic interval (e.g. a cluster pressure profile), use numpy’s logspace function instead of the usual linspace.
  • Split log axes: Sometimes you want log axes for a plot that includes both positive and negative values. Rather than messing around with taking the absolute value of the negative numbers and then changing the line style, you can use SymmetricalLogScale.

About Phil Bull

I'm a theoretical cosmologist, currently working as a NASA NPP fellow at JPL/Caltech in Pasadena, CA. My research focuses on the effects of inhomogeneities on the evolution of the Universe and how we measure it. I'm also keen on stochastic processes, scientific computing, the philosophy of science, and open source stuff. View all posts by Phil Bull

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: