bar3 Axis labels don't reflect real data

2 ビュー (過去 30 日間)
Austin
Austin 2013 年 6 月 17 日
コメント済み: Eric T 2015 年 3 月 11 日
I'm trying to plot Z bars against X and Y with more than a few data points. I would like the x and y axis labels to be the real x and y data. Using the example code below, each x and y bar should correspond to its X and Y axis data - but they don't. Plus, the tables change as I re-size the chart. I'm sure I'm just missing something simple.
Here's what I'm trying to accomplish, as shown in Excel: http://mutant.dnsalias.com/ctrx.pdf
surf() plots the correct axis, but the data points are not really connected in real life, so that plot is not really appropriate.
Here's and example:
format shortg
xAxis = sort(10*rand(20,1));
sprintf('XMin: %5f xMax: %5f', [min(xAxis) max(xAxis)])
yAxis = sort(30*rand(30,1));
sprintf('yMin: %5f yMax: %5f', [min(yAxis) max(yAxis)])
bar3(rand(20,30));
set(gca,'XTickLabel',xAxis)
set(gca,'YTickLabel',yAxis)

回答 (2 件)

Tom
Tom 2013 年 6 月 17 日
Try scaling the tick marks based on the limits you've defined:
format shortg
xAxis = sort(10*rand(20,1));
sprintf('XMin: %5f xMax: %5f', [min(xAxis) max(xAxis)])
yAxis = sort(30*rand(30,1));
sprintf('yMin: %5f yMax: %5f', [min(yAxis) max(yAxis)])
bar3(rand(20,30));
tick = get(gca,{'XTick','YTick'});
x = linspace(min(xAxis),max(xAxis),length(tick{1}));
y = linspace(min(yAxis),max(yAxis),length(tick{2}));
set(gca,'XTickLabel',x)
set(gca,'YTickLabel',y)
  2 件のコメント
Austin
Austin 2013 年 6 月 17 日
Works better - but is there a way to label with the "exact" values? Take a look at the linked excel chart. That is exactly what I'm trying to accomplish in Matlab.
Thx
Eric T
Eric T 2015 年 3 月 11 日
Yes, the above isn't really an answer it doesn't let you set the actual x and y values, but only their appearance.

サインインしてコメントする。


Madison
Madison 2014 年 2 月 26 日
This was really helpful. Thanks!

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by