How to split a contourf plot into two sections with different zooms
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
Mike Garrity
le 4 Mai 2015
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 commentaires
Mike Garrity
le 4 Mai 2015
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');
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!