title: Can I use matplotlib.units to switch between the units displayed on a graph?
body: <p>I’m using matplotlib to render graphs in a desktop application and I’m a little confused about matplotlib’s support of units. I want to let the user change the units shown on the <em>x</em> axis of a graph: all calculations will be done in nanometers, but the graph can be shown in either nanometers or gigahertz. (Note that there’s an inverse, not linear, relationship between these two units.)</p>
  
  <p>There are two obvious ways to do this: “manually” or using matplotlib. In the former case matplotlib wouldn’t know anything about units; when the user changed the units I’d just recalculate all of my data points, change the axes’ bounds and labels, and tell matplotlib to redraw. But I’m hopeful that matplotlib has built-in functionality to do the same thing.</p>
  
  <p>There is some <a href="http://matplotlib.org/api/units_api.html">light documentation about <code>matplotlib.units</code></a>, but as far as I can tell this is intended for plotting arrays of user-specified objects instead of arrays of, say, floats. My data actually is an array of floats, and since there are hundreds of thousands of data points per graph I can’t wrap each value in some custom model class. (Even <a href="http://matplotlib.org/examples/units/evans_test.html">this simple example</a> wraps each data point in a model class, and the entire example is so generic I can’t tell how I’d adapt it for my needs.) In any case, the original data points always have the same units, so the values only ever need to be converted <em>to</em> another unit.</p>
  
  <p>How can I tell matplotlib about my units and then just use <code>axes.set_xunit</code> or something to change between them?</p>