2D Graphs behind each other in 3D. Something like bar3

2 次查看(过去 30 天)
Hey,
I'd like to create a graph similar to the one in the picture number 78 (Abb. 78) from the following link http://www.elite.tugraz.at/Jungbauer/4.htm. How can I plot the graph with three different y-axes? And how is it possible to make the bars in 3D but keep the axes in 2D?
Here is a little example from what I have tried so far:
x = [1 2 3 4 5]; y1 = [2; 4; 6; 8; 10]; y2 = [4; 8; 12; 16; 20]; y3 = [6; 12; 18; 24; 30]; Y = [y1 y2 y3]; bar3(x,Y)
Thanks for any help! Mirco

回答(2 个)

Andreas Goser
Andreas Goser 2011-2-14
For me, this looks like this can be accomplished by BAR3 / BAR3H

Ben Tordoff
Ben Tordoff 2011-2-14
Hi Mirco,
the way that PLOTYY works (and most of the other multi Y-axis MATLAB plots I've seen) is to have multiple axes objects and to link together their X limits and ticks. LINKPROP is your friend here. This is somewhat harder in 3D than 2D, but something like the code below is probably the best way to approach this.
If you wanted to be really smart about it you could use a single axes object to draw the bars having previously scaled them all to some normalized coordinate frame. You can then use additional axes objects just to draw the Y-ticks and labels, although you have to synchronize the axes positions very carefully. This would give you the lines between the separate plots. I have done this in the past and it can work, but it is a lot of effort. You'll have to decide if the investment of time is worth it!
For the particular plot you mention, the third dimension does not contain any data and stacked 2D plots of the same data provides a much clearer view. 3D can be useful, but it isn't adding much here (infact it makes comparing values at corresponding X positions harder). I've included the stacked 2D view below for comparison.
Hope that helps.
Ben
%%%%%%%%
x = [1 2 3 4 5];
y1 = [0.2; 0.4; 0.6; 0.8; 1.0];
y2 = [40; 80; 120; 160; 200];
y3 = [6; 12; 18; 24; 30];
%%In 3D
fig = figure( 'Name', 'Multi Y-Axis 3D bar plots' );
plotSize = [0.35 0.5];
viewAngle = [-45 45];
% Plot each set of bars on its own axes so that you get independent Y-axes
ax3 = axes( 'Position', [0.5 0.4 plotSize] );
bar3( x, y3, 'r' )
view( ax3, viewAngle )
ax2 = axes( 'Position', [0.3 0.25 plotSize] );
bar3( x, y2, 'g' )
view( ax2, viewAngle )
ax1 = axes( 'Position', [0.1 0.1 plotSize] );
bar3( x, y1 )
view( ax1, viewAngle )
% Remove tick labels from all sub-axes
set( [ax2,ax3], 'YTickLabel', {} );
% Link the plot x-axes together
setappdata( fig, 'Linker', linkprop( [ax1,ax2,ax3], {'YTick','YLim'} ) )
%%In 2D
fig = figure( 'Name', 'Multi Y-Axis 2D bar plots' );
plotSize = [0.8 0.25];
spacing = 0.05;
% Plot each set of bars on its own axes so that you get independent Y-axes
ax3 = axes( 'Position', [0.1 0.1+2*(spacing+plotSize(2)) plotSize] );
bar( x, y3, 'r' )
grid( ax3, 'on' )
ax2 = axes( 'Position', [0.1 0.1+(spacing+plotSize(2)) plotSize] );
bar( x, y2, 'g' )
grid( ax2, 'on' )
ax1 = axes( 'Position', [0.1 0.1 plotSize] );
bar( x, y1 )
grid( ax1, 'on' )
% Remove tick labels from all sub-axes
set( [ax2,ax3], 'XTickLabel', {} );
% Link the plot x-axes together
setappdata( fig, 'Linker', linkprop( [ax1,ax2,ax3], {'XTick','XLim'} ) )

类别

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