Showing posts with label MATLAB. Show all posts
Showing posts with label MATLAB. Show all posts

Sunday, December 14, 2014

Choosing colors for scientific visualization: the RGB gamut in CIELUV

I make a lot of plots for work, and color is a very useful way to convey information. These colors are usually represented in RGB, especially when dealing with colors on a computer screen.

However, RGB does not do a good job of representing human perception of color. You will find that [0 255 0] (green) appears much brighter than [255 0 0] (red), which is in turn brighter than [0 0 255] (blue). Furthermore, if you sample uniformly from the RGB space, you will find that an unreasonably large fraction of this appears green.

There have been many attempts to parameterize color in a way that is more closely related to human perception. The one that I've been using is the CIE 1976 (L*, u*, v*) color space, aka CIELUV. The L* is supposed to represent the apparent brightness, and (u*, v*) parameterize the apparent color. It is supposed to do this in such a way that the distance between two points in the CIELUV space corresponds to how distinguishable the corresponding colors are to a human with trichromatic vision.

However, not everything in this color space is representable on a computer monitor. That is, not all of those points will fall within the RGB gamut. So without further ado, I present the RGB gamut in the CIELUV color space:

The boundaries are where one or more of the RGB coordinates saturate.

According to my friend, who (like 7% of American males) has impaired color vision, the color contrast is greatest traveling along the vertical (v*) axis. Of course, there are many ways in which your color vision could be impaired, so his experience is not representative of all color blind people.

More plots below:

Monday, February 27, 2012

Multiple axes in MATLAB

How to make plots like the ones from this post:


Wednesday, January 25, 2012

Making MATLAB figures prettier

Changing the default line style (e.g. for printing in black-and-white):
set(0,'DefaultAxesLineStyleOrder',{'-','--',':'})
set(0,'DefaultAxesColorOrder',[0 0 0])

For dotted lines exported to .eps:
http://www.mathworks.com/matlabcentral/fileexchange/15743-fix-dashed-and-dotted-lines-in-eps-export
Usage:
print -depsc myfigure.eps
fix_dottedline('myfigure.eps')

More to come...

Tuesday, January 17, 2012

Mathematica for MATLAB users

I plan on expanding this post later; for now it's just a place to put this very useful link:

http://meng6.net/pages/matlab_mathematica_equivalent_commands/

Clear all:
ClearAll["Global`*"]

Defining a matrix: A = [1 2 ; 3 4]
A = {{1, 2}, {3, 4}}

This gives you something horrendous:
Integrate[ 1/(x + 1)^2 , {x , y, 1} 
But this gives you the nice expression that you probably wanted:
Simplify[Integrate[ 1/(x + 1)^2 , {x , y, 1} ], {y > 0 , y < 1}]


Saturday, February 26, 2011

MATLAB transpose

Big discovery for today: MATLAB's transpose function (denoted as ') is actually the conjugate transpose! The syntax for the non-conjugate transpose is .'

This caused lots of frustration today.

Thursday, February 17, 2011

MATLAB Bode plot units

Sometimes I want Bode plots with frequency in Hz rather than rad/s, or a magnitude in absolute units rather than dB. I've been using workarounds like calling bode with output arguments and plotting it myself, or frequency-shifting the transfer function (for frequency in Hz).

But it turns out you can change it! Call ltiview, and you can use the GUI to change the default axis settings (File -> Toolbox Preferences).