# Matlab Help - contourf with a log2 yaxis

**URL:** <https://boards.straightdope.com/t/matlab-help-contourf-with-a-log2-yaxis/344527>\
**Category:** Factual Questions\
**Created:** [February 14, 2006, 8:58pm UTC](https://boards.straightdope.com/t/matlab-help-contourf-with-a-log2-yaxis/344527 "2006-02-14T20:58:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![audiobottle](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@audiobottle](https://boards.straightdope.com/u/audiobottle)\
**Post date:** [February 14, 2006, 8:58pm UTC](https://boards.straightdope.com/t/matlab-help-contourf-with-a-log2-yaxis/344527/1 "2006-02-14T20:58:09Z")

</div>

So I’ve got a big matrix of data, say 100 by 100. Now I can do a nice filled contour plot by using contourf and then changing the yaxis to a log scale by using the set(gca,‘YScale’,‘log’) command, but I need a log2 axis on the y side. Is there a way I can do this easily without having to write a new function? I’ve looked through the axes properties but haven’t found anything. I’ve also thought of recreating my matrix so that the values repeat on a level of 2^whatever, but I’m not entirely sure that’s the same thing. Any other ideas?

---

<div class="post-metadata">

**Author:** ![Omphaloskeptic](https://avatars.discourse-cdn.com/v4/letter/o/bcef8e/32.png) [@Omphaloskeptic](https://boards.straightdope.com/u/Omphaloskeptic)\
**Post date:** [February 14, 2006, 9:57pm UTC](https://boards.straightdope.com/t/matlab-help-contourf-with-a-log2-yaxis/344527/2 "2006-02-14T21:57:24Z")

</div>

The log[sub]2[/sub] (or to any other base) is proportional to the log[sub]10[/sub], so your contour plot will look the same under whichever base you choose. Do you just mean that you’d like the marked values along the y axis to be octaves (e.g., 1, 2, 4, 8, …) rather than decades (1, 10, 100, …)? You can do this with something like  
set(gca,‘YTick’,2.^(emin:emax))  
to explicitly set the tick marks. You might want to follow this with  
set(gca,‘YTickLabel’,sprintf(‘2^%d’,emin:emax))  
if your exponents are large enough that the powers of 2 are unwieldy to read. I don’t know of any easy way to get the exponential notation that SEMILOGY makes, though you could do that with multiple calls to TEXT.

Note that if your contour plot spans a large range in y (ymax/ymin \>\> 1) then the contours will not be very smooth, in the log-scaled plot, for small y (due to poor sampling there). If you are generating this matrix you may want to generate it using log-scaled spacing in the y direction (e.g., using y values of 2.^(0:0.01:1)); now a plain contour plot will be log-scaled in y, and you can then change the y labels (as above) to read as powers of 2.

---

<div class="post-metadata">

**Author:** ![audiobottle](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@audiobottle](https://boards.straightdope.com/u/audiobottle)\
**Post date:** [February 15, 2006, 12:35pm UTC](https://boards.straightdope.com/t/matlab-help-contourf-with-a-log2-yaxis/344527/3 "2006-02-15T12:35:37Z")

</div>

Hmm… I hadn’t thought about the log[sub]10[/sub]-log[sub]2[/sub] relationship. I guess now my question is, how can I label the yaxis so that the tick marks are linearly spaced apart instead of logarithmically spaced? Would I just have to create a new axis overtop the old one and label that one?

---

<div class="post-metadata">

**Author:** ![audiobottle](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@audiobottle](https://boards.straightdope.com/u/audiobottle)\
**Post date:** [February 15, 2006, 1:50pm UTC](https://boards.straightdope.com/t/matlab-help-contourf-with-a-log2-yaxis/344527/4 "2006-02-15T13:50:48Z")

</div>

Actually, forget the log stuff. I just realized I was told incorrect information. Anyway, this is what I actually need to plot. Say I have random data corresponding to linearly increasing x. The value of x itself corresponds inversely to another value, say w. That is x = k/w. How can I plot my data so that its arranged linearly by the w instead of by the x? Does this even make sense to anyone other than me?

---

<div class="post-metadata">

**Author:** ![audiobottle](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@audiobottle](https://boards.straightdope.com/u/audiobottle)\
**Post date:** [February 15, 2006, 3:32pm UTC](https://boards.straightdope.com/t/matlab-help-contourf-with-a-log2-yaxis/344527/5 "2006-02-15T15:32:36Z")

</div>

Since I’ve realized the obvious and simple solution, I am asking a mod to close this. Thaks for the advice.
