Thursday, September 18, 2014

Points of View from Nature Methods

Via the UW Design Help Desk I discovered the Points of View column at Nature Methods. While Points of View has been discontinued, there's a lot of great content in the 35 columns that were published, which are compiled here. Spend a few minutes poking around and read about using color effectively, improving figure clarity, exploring data, and more.

Thursday, December 5, 2013

Figure width

I had a breakthrough with a figure today. I had made a plot that I really didn't like, and I just couldn't figure out the way to make it better. The answer ended up being that I needed to make the figure narrower.

Tufte talks about data angles and says that data looks best when the majority of the data falls on roughly a 45 degree angle. Obviously, there are many exceptions to this rule, but in my case today, it really helped my figure.

Here is an early version of this figure. The goal is to see how a number of properties at four different locations vary throughout an annual cycle. Some of the cycles can be seen, but overall no clear message from the figure stands out.

Early, wide version of the figure


Here is the updated version of the figure.

Revised, narrow version of the figure. (The height is the same as the older version.)

It is much easier to see how the annual cycles change at the four locations with the narrower figure. Considering, that I only have 12 data points along the x-axis for each variable and position, I did not need such a wide figure. Now, my slopes are also steeper which makes the variability of the annual cycles more obvious. (A lot more data is falling at 45 degree angles like Tufte suggests.)

I made a few other changes too. I care most about the data from 23W and 140W, and I care least about the data from 170W. Therefore, I plotted the least important data in a light gray and the most important data in bold red and black. It's now much easier to differentiate the annual cycles at each position.

If I were to publish this figure, I might remove the gridlines. Are they too much chart clutter? They were, however, helpful today though when I was comparing my results to older published results of similar variables. (A quick note on gridlines: I much prefer my very light gray solid grid lines compared to the matlab default of black dots.)




Monday, November 11, 2013

Hold On!

There's a weird bug in MATLAB with the function HOLD ON. I'm sure we've all used HOLD ON when making figure — it needs to be used in order to plot multiple lines. However, WHERE the HOLD ON command is used makes a big different in the appearance of plots.

For instance, if I were to write the commands:

% define some function
x = 0:0.1:2*pi;
y1 = sin(x);
y2 = cos(x);

% plot the functions
figure

% subplot 1: plot the first function BEFORE using HOLD ON
subplot(211)
plot(x,y1,'linewidth',2)
hold on
plot(x,y2,'r','linewidth',2)

% subplot 2: plot the first function AFTER using HOLD ON
subplot(212)
hold on
plot(x,y1,'linewidth',2)
plot(x,y2,'r','linewidth',2)


The following figure results:




There is a border around the plot on all four sides in the top subplot, whereas there is only a border on the bottom and left in the bottom subplot. This difference is due ONLY to the position of the HOLD ON command. 

When HOLD ON comes AFTER the first function is plotted, an entire border is plotted. Whereas, when HOLD ON comes BEFORE the first function is plotted, the border is only on the left and bottom.


The position of HOLD ON not only changes the plot borders, but it can change how the data is plotted, such as with SEMILOGY:

% define a random function that will vary over a large range
x = 1:100;
y = 2.^(rand(100,1)*100);

figure

% plot SEMILOGY before HOLD ON is used
subplot(211)
semilogy(x,y,'linewidth',2)
hold on

% plot SEMILOGY after HOLD ON is used
subplot(212)
hold on
semilogy(x,y,'linewidth',2)

The following figure results:




In this case, not only is there the same difference with the subplot borders, but when HOLD ON is used BEFORE SEMILOGY, MATLAB just uses a regular plot command rather than SEMILOGY as seen in the second subplot. HOLD ON must not be used before SEMILOGY for SEMILOGY to plot correctly. 


I was confused by this bug for quite a while, not understanding why sometimes I would get an entire border around my figures and sometimes I wouldn't. Once I figured out that it was the placement of the HOLD ON command that changed the border, I actually started strategically placing HOLD ON to avoid having to use the BOX ON and BOX OFF commands to turn the top and right borders on and off. 

It was today that I realized that the placement of HOLD ON also is what prevents SEMILOGY from working correctly! Knowing this bug will prevent many headaches in the future.

Friday, September 27, 2013

Fake colorbar

Often I want to plot two (or many) datasets that have the same time vector. I simply use the SUBPLOT command in MATLAB to do so. A problem arises, however, when one of these datasets happens to be three-dimensional — something that I want to plot with pcolor. When I add a colorbar to that subplot, the time-axis (x-axis) no longer lines up with the other subplots.


BAD: The time-axes for (a) and (b) have different scales because of the colorbar in (b).


To fix this problem, I wrote a simple function called FAKECOLORBAR which changes the size of the subplot that does not require a colorbar so it matches the subplot with the colorbar.



GOOD: The time-axes for (a) and (b) now align because I used FAKECOLORBAR on (a)


Now, if someone could just tell me how to fix the phi in the title of (b) so that it is not partially cutoff...

Oh, and these data will in a jagged and blocky way unless I subtract 2000 years from the time vector, which is why the x-axis label in (b) says "January 7" instead of "January 2007." I'm sure others have run into this problem before. Another problem for another day.


Friday, August 9, 2013

Undocking figures

My coworker, Cheryl, was so excited today when she realized that by undocking her matlab figures she can now save them the way she wants to. See the link on the matlab forum: http://www.mathworks.com/matlabcentral/newsreader/view_thread/245320. Sometimes it's these little things that are so unintuitive to fix that can make figure creation more difficult than it needs to be.

I've been out of the country for the past 8 months and away from matlab (and a computer). Now I've returned to work and hope to have many new and exciting thoughts about figure design.


Friday, October 5, 2012

Junk Charts

I was typing in a web address in my browser, and one of the auto-complete suggestions was for Junk Charts, a blog about bad figures found in the wild.  I had visited it a while back but forgotten about it.  Check it out for some particularly egregious examples of chart junk.

Tuesday, September 11, 2012

FakeColor

Back on May 17, I posted a method that my officemates Nick and Noel use to plot multiple colormaps in one figure. Andy Pickering has taken their idea and written a function called 'FakeColor.' Really useful for making multiple contour plots with different colormaps.

Thanks Andy!