【问题标题】:plotting 3D bar graph in matlab or excel在 matlab 或 excel 中绘制 3D 条形图
【发布时间】:2011-11-14 09:02:59
【问题描述】:

我需要在 matlab 或 excel 中绘制一个 3D 条形图。我将在 x 轴上使用一些日期,在 y 轴上使用时间,在 z 轴上使用一些数量。 csv 文件中的每条记录看起来像...

4 月 18 日,21 日,139.45

我不确定如何正确执行此操作。谁能帮帮我。我尝试使用excel的数据透视图。但是,我无法操纵轴并在每个刻度之间使用适当的空间。

谢谢 凯撒

【问题讨论】:

    标签: excel matlab file-io plot bar-chart


    【解决方案1】:

    由于问题缺乏细节,我举个例子来说明。

    考虑以下代码:

    %# read file contents: date,time,value
    fid = fopen('data.csv','rt');
    C = textscan(fid, '%s %s %f', 'Delimiter',',');
    fclose(fid);
    
    %# correctly reshape the data, and extract x/y labels
    num = 5;
    d = reshape(C{1},num,[]); d = d(1,:);
    t = reshape(C{2},num,[]); t = t(:,1);
    Z = reshape(C{3},num,[]);
    
    %# plot 3D bars
    bar3(Z)
    xlabel('date'), ylabel('time'), zlabel('value')
    set(gca, 'XTickLabel',d, 'YTickLabel',t)
    

    我在以下数据文件上运行:

    数据.csv

    18-Apr,00:00,0.85535
    18-Apr,03:00,0.38287
    18-Apr,06:00,0.084649
    18-Apr,09:00,0.73387
    18-Apr,12:00,0.33199
    19-Apr,00:00,0.83975
    19-Apr,03:00,0.37172
    19-Apr,06:00,0.82822
    19-Apr,09:00,0.17652
    19-Apr,12:00,0.12952
    20-Apr,00:00,0.87988
    20-Apr,03:00,0.044079
    20-Apr,06:00,0.68672
    20-Apr,09:00,0.73377
    20-Apr,12:00,0.43717
    21-Apr,00:00,0.37984
    21-Apr,03:00,0.97966
    21-Apr,06:00,0.39899
    21-Apr,09:00,0.44019
    21-Apr,12:00,0.15681
    22-Apr,00:00,0.32603
    22-Apr,03:00,0.31406
    22-Apr,06:00,0.8945
    22-Apr,09:00,0.24702
    22-Apr,12:00,0.31068
    23-Apr,00:00,0.40887
    23-Apr,03:00,0.70801
    23-Apr,06:00,0.14364
    23-Apr,09:00,0.87132
    23-Apr,12:00,0.083156
    24-Apr,00:00,0.46174
    24-Apr,03:00,0.030389
    24-Apr,06:00,0.7532
    24-Apr,09:00,0.70004
    24-Apr,12:00,0.21451
    25-Apr,00:00,0.6799
    25-Apr,03:00,0.55729
    25-Apr,06:00,0.85068
    25-Apr,09:00,0.55857
    25-Apr,12:00,0.90177
    26-Apr,00:00,0.41952
    26-Apr,03:00,0.35813
    26-Apr,06:00,0.48899
    26-Apr,09:00,0.25596
    26-Apr,12:00,0.92917
    27-Apr,00:00,0.46676
    27-Apr,03:00,0.25401
    27-Apr,06:00,0.43122
    27-Apr,09:00,0.70253
    27-Apr,12:00,0.40233
    

    【讨论】:

    • @@Amro,您介意说明如何更改 z 轴上的范围吗?例如,要显示从 [0.65,1] 开始的值范围内的条形,而不是从 [0,1] 开始。我尝试使用ZLim([zmin zmax]);,但 3D 条的格式完全松散。
    【解决方案2】:

    使用 MATLAB 的 CSV reading functions(或自己编写),然后使用 bar3 显示数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多