Cubehelix Colormap for Python

No comments:
I have been transitioning to using Python for more and more of my research, which has gone relatively smoothly I'm happy to say! Within the last ~2 years Python's libraries and documentation for things astronomical has reached a "critical mass", and making the transition for most things has never been easier!

However, one little problem still eats at my soul every day I use Python, specifically Matplotlib: the colors in figures are usually terrible!

My absolute favorite color map (at least for now) is cubehelix. I have written about this color map before:
CUBEHELIX, or How I Learn to Love Black & White Printers,
I also wrote the version for IDL used in the Coyote Library, and helped bring a version to the Tableau community last year.

A real cubehelix version for Python

Matplotlib already has the default cubehelix colormap built in, as well as several excellent colormaps that properly desaturate. What makes the cubehelix algorithm so powerful is that it defines a family of colormaps that all desaturate properly. This is what is missing currently in Matplotlib.

The Python community has a strong "put up or shut up" attitude that I love, so I spent a few hours translating my IDL implementation of cubehelix in to Python!

The code is available on github
Try it out, it's dead simple to use!

Some Examples

import numpy as np
import matplotlib.pyplot as plt
import cubehelix 
# set up some simple data to plot
x = np.random.randn(10000)
y = np.random.randn(10000)

# create the default "cubehelix" colormap
cx1 = cubehelix.cmap()

# Reverse of the default "cubehelix" colormap
# I think this is more appropriate for density maps, 
# as intensity corresponds with density.
cx2 = cubehelix.cmap(reverse=True)

# My favorite flavor of "cubehelix", 
# mostly blue with a small hue change
cx3 = cubehelix.cmap(reverse=True, start=0.3, rot=-0.5)

# Another good version, mostly using red/purples
cx4 = cubehelix.cmap(reverse=True, start=0., rot=0.5)

Apparently I've just reinvented the cubehelix wheel! I can live with that

Astronomical Map Projection

No comments:
I've been enjoying a cool website called Astronomy Image Explorer (, which aims to provide image search for our scientific literature.

I think this is a brilliant idea because most astronomers read a lot of journal papers, often searching through them for a very specific result or point. As such, the graphs are usually the most memorable piece of the paper. (Thus: you should invest time in to making your graphs clear and easy to read, but I digress) is somewhat limited in function compared to other image searching tools online. However, they specifically connect the image with figure captions and authors, which is awesome. While I'd still like to see things like TinEye (reverse image search), expanded logic operators, and more API support included, is a really neat idea!

I was playing with while at the "Thinking with your Eyes" symposium and wondered: what we could learn about the style/type of graphs and maps astronomers use? This is a broad question, and really in the domain of HCI/visualization research.

One simple avenue was to focus on maps, specifically map projections in astronomy. Often in figure captions the authors will state the type of map projection (which I would encourage!) particularly if the map covers a large field of view and distortion/projection effects are significant. So for a simple case study, I went looking for how many occurrences of different map projection names I could find in figure captions.

Of course this is not comprehensive in any way, but the results are interesting!

I'm just counting up the number of results when searching for each term. In the case of "Robinson", I did a search for "map" within the search for "robinson" (too many authors named Robinson came up).  The distribution matches my intuition, as I see mostly Aitoff (or Hammer-Aitoff) projections in papers. I also don't know what fraction of papers are indexed in this search.

A few projections I didn't find any results for include: Eckert, Pseudocylindrical, conic, gnomic, Dymaxion, and Goode Homolosine. A challenge for a future journal article, perhaps?

Absurd Graphs

Here are two random things I made this week.

I wondered what a map made of wood made with a computer might look like. Here is the answer.
Each time I generate the graph it comes out uniquely, so that's mildly interesting.

Summing up most of my knowledge from my graduate MHD course.

Report: Gender in AAS Talks

Today I'm proud to announce that my AAS 223 Hack Day project is finally finished! Our "paper" (really an informal report) on the study of gender in AAS talks has hit astro-ph:

This all started about 6 months ago when I was attending a different astronomy conference. I observed that the gender ratio for speakers seemed well balanced, as did the audience. Both were perhaps 60%/40% (Men/Women). However, the questions mostly seemed to be asked by men!

So I decided to organize a volunteer effort to study this. We collected data using a simple web-form (that Morgan Fouesneau graciously helped me make), and asked conference attendees to record the gender of every speaker and every question asker for talks they attended.

We got over 300 submissions! I was going to be happy with 100, and figured I'd have to beg a few friends to participate. This was enough data to make some interesting plots... and also just enough data to know that we need more data!

Here are a few highlights from the study:

1. Men ask disproportionally more questions than women in talks.

FS FQ = Female Speaker, Female Questions,
FS MQ = Female Speaker Male Questions, etc

We were very glad to see that the gender ratio of all the speakers matched that of the conference participants. This also closely matches the gender ratio of astronomers under the age of ~40 as reported in the AAS Demographics survey recently.

2. Women are asked slightly more questions per talk than men

Blue is talks by men, green is talks by women
The significance of this result is debatable, but it's the first time I've seen data like this. I wonder how this varies with sub-field of the talks...

3. The gender of the session chair has a strong impact on the gender ratio of the questioners.

FC FQ = Female Chair, Female Questions,
FC MQ = Female Chair Male Questions, etc
This result shocked me, and begs to be studied further. The session chair seems to greatly impacts the gender ratio of the questions being asked. What does this mean?! Are male session chairs preferentially selecting male questions? Are women less likely to speak up when an additional man is standing in front?

We need data on the format of the session to understand the origin of this result, and to make actionable suggestions/best-practices for future conferences!

The Future:

I want to conduct a more controlled follow up study! It's clear to me that there's more to learn, and maybe ways we can improve how our conferences are conducted.

But I'll need help doing it!

The upcoming AAS 225 in Seattle (Jan 2015) would be a perfect time to do a follow-up study. We need to gather more detailed data from every talk. A big volunteer effort might get us there, but if the AAS is interested in helping that could be a huge shot in the arm. We did this project with $0 spent and only social media / friends to help advertise. With the AAS's help we could get this data and help make our annual meetings even better!

Lastly, a huge thanks to the wonderful volunteers who sent us data, the organizers and sponsors of AAS Hack Day, and [Morgan, Erin, Alex, Katja, Laura] for making the analysis/writing happen!

Update: this appears to be my 100th blog post on If We Assume! 
Here's a sweet badge I awarded myself...
Related Posts Plugin for WordPress, Blogger...