How to split a contourf plot into two sections with different zooms

조회 수: 6 (최근 30일)
Leon
Leon 2015년 5월 4일
댓글: Leon 2015년 5월 4일
For example, if I am plotting a vertical section of water temperature from surface to 5000 meters, the portion of the plot from surface to 1000 meters may be too squeezed to show the real story there.
How do I split the contour plots into two panels, with zoomed out portion from surface to 1000 meters, and normal zoom portion from 1000 meters to 5000 meters?
Attached is an example that was plotted using Surfer.

채택된 답변

Mike Garrity
Mike Garrity 2015년 5월 4일
The only builtin non-linear scale is log, but you can roll your own. Here's a simple example:
%%Start with peaks
[x,y,z] = peaks;
%%Two linear equations meeting at y=cutoff
cutoff = 2;
scale = 5;
%%Mask of all Y values above cutoff
above = y>cutoff;
%%Compute scaled Y values
y2 = y;
y2(above) = cutoff + (y(above)-cutoff) * scale;
%%Create contour with y2
contourf(x,y2,z)
%%Fix up tick labels
ax = gca;
yt = ax.YTick;
above = yt>cutoff;
yt(above) = cutoff+(yt(above)-cutoff)/scale;
ax.YTickLabel = yt;
This uses two scales and abruptly switches between them at the cutoff. I've never been very fond of this approach. I think that it's better to use a function with a smooth transition. The basic idea is the same though. You create a scaled copy of your Y coordinates and create the contour with that. Then you fix-up the YTickLabel to be the inverse.
Does that make sense?
  댓글 수: 6
Mike Garrity
Mike Garrity 2015년 5월 4일
You're right Sean. I was making it too complicated, wasn't I?
Here's a simple implementation of Sean's idea:
margin = .075;
ratio = 3;
h1 = (1-3*margin) / (ratio+1);
h2 = h1*ratio;
ax1 = axes('Position',[.13 margin .775 h1]);
ax2 = axes('Position',[.13, 2*margin+h1, .775, h2]);
[x,y,z] = peaks;
contourf(ax1,x,y,z);
contourf(ax2,x,y,z);
cutoff = 0;
set(ax1,'YLim',[-inf cutoff]);
set(ax2,'YLim',[cutoff inf],'XAxisLocation','top');
Leon
Leon 2015년 5월 4일
Thank you so much, Mike and Sean!
This is very helpful.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by