当前位置:   article > 正文

大地测量观测数据可视化MATLAB工具箱:(1)时间序列、统计数据可视化_visbundle

visbundle

大地测量的各类观测结果需要进行可视化才能更好应用了后续的分析和解释,这里我分享德国斯图加特大学大地测量研究所的一个工具包(VISBUNDLE)。

(1)三维柱状图渲染

  1. H = magic(10);
  2. H = [H(1:5,:), -H(6:10,:)];
  3. H(3,5) = NaN; H(3,7) = Inf;
  4. H(5,1) = -Inf;H(1,9) = 0;
  5. figure
  6. subplot(231);barplotcol(H,'floor'); title('ColorOption: floor')
  7. subplot(232);barplotcol(H','floor'); title('ColorOption: floor')
  8. subplot(234);barplotcol(H,'building'); title('ColorOption: building')
  9. subplot(235);barplotcol(H','building'); title('ColorOption: building')
  10. subplot(2,3,[3,6]); bar3(H); title('bar3.m'),colormap jet

barplotco.m函数:

  1. function handle = barplotcol(H,ColorOption,maxRowCol)
  2. % handle = barplotcol(H,ColorOption,maxRowCol)
  3. % handle = barplotcol(H)
  4. %
  5. % BARPLOTCOL visualizes a data matrix as a "3D city block". The basic idea is
  6. % the routine bar3.m, but the color is refering to the height information
  7. % instead of the column of the matrix. Inf and NaN elmenents are replaced by
  8. % zero before visualization.
  9. %
  10. % IN:
  11. % H: ............ 2-dimensional data matrix [-][NxM]
  12. % ColorOption:... choice between ['string']
  13. % * 'floor': colored layers indicated the same height
  14. % * 'building': color indicates the value in the marix
  15. % maxRowCol:..... option to increase the maximal number of columns and rows [-][1x1]
  16. % default: no plot for more than 10000 elements
  17. %
  18. % OUT:
  19. % handle:........ handle of the graphics for further improvement
  20. %
  21. % See also: --
  22. %
  23. % sub-routines:
  24. % * --
  25. %
  26. % REMARKS:
  27. % * The size of the matrix is limited by the bar3.m function.
  28. % * For more than 10000 elements, the bar-routine is very slow and you
  29. % get an warning now. If you really want more, increase the limit by
  30. % the additional input of 'maxRowCol'.
  31. %
  32. % -------------------------------------------------------------------------
  33. % project: visBundle
  34. % -------------------------------------------------------------------------
  35. % authors:
  36. % Markus ANTONI (MA), GI, Uni Stuttgart
  37. % -------------------------------------------------------------------------
  38. % revision history:
  39. % 2021-05-04: MA, unified help text in VISBUNDLE
  40. % 2013-02-20: MA, renamed for visBundle
  41. % 2013-02-12: MR, prushed up of help text
  42. % 2010-10-21: MA, initial version at DEOS
  43. % -------------------------------------------------------------------------
  44. % license:
  45. % This program is free software; you can redistribute it and/or modify
  46. % it under the terms of the GNU General Public License as published by
  47. % the Free Software Foundation; either version 3 of the License, or
  48. % (at your option) any later version.
  49. %
  50. % This program is distributed in the hope that it will be useful, but
  51. % WITHOUT ANY WARRANTY; without even the implied warranty of
  52. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  53. % GNU General Public License for more details.
  54. %
  55. % You should have received a copy of the GNU General Public License
  56. % along with Octave; see the file COPYING.
  57. % If not, see <http://www.gnu.org/licenses/>.
  58. % -------------------------------------------------------------------------
  59. %% checking the input arguments
  60. narginchk(1,3)
  61. if nargin<2
  62. ColorOption = 'building';
  63. end
  64. if nargin<3
  65. maxRowCol = 10000;
  66. end
  67. % number of elements
  68. [row,column] = size(H);
  69. if row*column>maxRowCol
  70. warning('amount of elements is quite large for bar3, increase >> maxRowCol << if you really want this')
  71. return
  72. end
  73. %% removing NaN/Inf
  74. index = isnan(H);
  75. H(index) = 0;
  76. index = isinf(H);
  77. H(index) = 0;
  78. % basic is the function BAR3
  79. handle = bar3(H,'detached');
  80. row6 = row*6;
  81. set(handle,'FaceAlpha',1);
  82. set(gcf, 'Renderer', 'ZBuffer');
  83. switch ColorOption
  84. case 'building'
  85. % constant color per block
  86. for n=1:column
  87. index = logical(kron(H(:,n) == 0,ones(6,1)));
  88. colorData = get(handle(n),'ZData');
  89. colorData(index,:) = nan;
  90. % changing the color of all 6 faces per block
  91. for k = 1:6:row6;
  92. colordata1 = colorData(k:k+5,:);
  93. index1 = colordata1 == 0;
  94. colordata1(index1) = colordata1(2,2);
  95. colorData(k:k+5,:) = colordata1;
  96. end
  97. set(handle(n),'cData',colorData);
  98. end
  99. case 'floor'
  100. % equal color for equal height layer
  101. for n=1:column
  102. index = logical(kron(H(:,n) == 0,ones(6,1)));
  103. colorData = get(handle(n),'ZData');
  104. colorData(index,:) = nan;
  105. set(handle(n),'cData',colorData);
  106. end
  107. otherwise
  108. warning('chosen ''ColorOption'' is not implemented')
  109. end
  110. shading interp; axis tight;
  111. colorbar

结果图

(2)时间序列添加阴影

我之前介绍过一个添加阴影的函数,这里介绍的这个函数可以等间隔绘制阴影,或者不等间隔。

  1. figure;
  2. subplot(211);
  3. t = -5:.01:20;
  4. f1 = sin(t*pi);
  5. plot(t, f1); hold on;
  6. graypatch([-5,2,20], [-1.2,1.2], [-5:1:20],true);
  7. title('graypatch(..) with regular intervals');
  8. subplot(212);
  9. f2 = sin(sign(t).*sqrt(abs(t))*pi).*exp(-t/10);
  10. plot(t,f2); hold on;
  11. xStartEnd = [-5,-4;0,4; 16,20];
  12. graypatch(xStartEnd,[-3,3],[-5 -4 0 4 16 20]);
  13. title('graypatch(..) with irregular intervals');

graypatch.m函数:

  1. function h = graypatch(xStartEnd, Ylim, Xtick,white1)
  2. % h = graypatch(xStartEnd, Ylim, Xtick,white1)
  3. %
  4. % GRAYPATCH hightlights 'periodic' events by marking every second period
  5. % with an alternating white/gray backgroud. Graypatch can also deal with
  6. % non-equal time spans (see example).
  7. %
  8. % IN:
  9. % xStartEnd .. defines the time points of the events,
  10. % [start, period_increment, end] for regular spacing [1x3]
  11. % [T0, T1; T2, T3; ...] for irregular spacing [Nx2]
  12. % Ylim ....... limits of y-axis [1x2]
  13. % Xtick ...... labels on the x-axis (e.g. periods T*n) [1xN]
  14. % white1...... first patch is white for white1 = true (default) or [1x1]
  15. % gray for white1 = false
  16. %
  17. % OUT:
  18. % h:............ handle of the graphics for further improvement
  19. %
  20. % REMARKS:
  21. % * To avoid "hidden yticks", is recommanded to start with a white patch
  22. % which is the default in the new version
  23. %
  24. % -------------------------------------------------------------------------
  25. % project: visBundle
  26. % -------------------------------------------------------------------------
  27. % authors:
  28. % Markus ANTONI (MA), GI, Uni Stuttgart
  29. % Matthias ROTH (MR), GI, Uni Stuttgart
  30. % -------------------------------------------------------------------------
  31. % revision history:
  32. % 2021-05-04: MA, start with white patch to avoid hidden yticks
  33. % 2016-03-14: MR, brush-up help text; remove alpha bug: plotted gray
  34. % bars on top of the data, hence changing their color;
  35. % change code, that also fractions of periods are
  36. % possible
  37. % 2015-03-17: MA, some modifications
  38. % 2015-02-19: MA, initial version, based on gray_patch of
  39. % Mohammad J. TOURIAN
  40. % -------------------------------------------------------------------------
  41. % license:
  42. % This program is free software; you can redistribute it and/or modify
  43. % it under the terms of the GNU General Public License as published by
  44. % the Free Software Foundation; either version 3 of the License, or
  45. % (at your option) any later version.
  46. %
  47. % This program is distributed in the hope that it will be useful, but
  48. % WITHOUT ANY WARRANTY; without even the implied warranty of
  49. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50. % GNU General Public License for more details.
  51. %
  52. % You should have received a copy of the GNU General Public License
  53. % along with Octave; see the file COPYING.
  54. % If not, see <http://www.gnu.org/licenses/>.
  55. % -------------------------------------------------------------------------
  56. %% checking the input arguments
  57. narginchk(2,4)
  58. if nargin < 4, white1 = true; end
  59. if nargin < 3, Xtick = []; end
  60. if ~isscalar(white1), error('argument ''white1'' must be scalar'); end
  61. if ~islogical(white1), error('argument ''white1'' must be boolian'); end
  62. if isscalar(Xtick) && islogical(Xtick), white1 = Xtick; end
  63. %% create Start-End matrix from [start, period_increment, end]
  64. if numel(xStartEnd) == 3
  65. V(1, :) = xStartEnd(1)+white1*xStartEnd(2):(2*xStartEnd(2)):xStartEnd(3);
  66. V(2, :) = V(1, :) + xStartEnd(2);
  67. V(V > xStartEnd(3)) = xStartEnd(3);
  68. else % we expect non-periodic elements
  69. V = xStartEnd';
  70. end
  71. blocks = numel(V(1, :));
  72. if blocks < 2
  73. warning('graypatch requires more than 1 patch');
  74. return
  75. end
  76. %% prepate patch coordinates
  77. X = V([1; 1; 2; 2], 1:blocks);
  78. Y = repmat(Ylim([1, 2, 2, 1])', 1, blocks);
  79. Z = ones(size(X));
  80. %% gray blocks
  81. h = patch(X, Y, Z, 'facecolor', [0.94 0.94 0.94], 'LineStyle', ':'); hold on;
  82. try
  83. uistack(h, 'bottom'); % put gray blocks on lowest graphics layer
  84. catch
  85. warning('''uistack''-routine is missing, gray blocks are not in lowest layer now')
  86. end
  87. grid off;
  88. %% labeling, grid
  89. Xlim = [min(V(:)),max(V(:))];
  90. if nargin > 2
  91. if isvector(Xtick) == 1 && numel(Xtick) > 1
  92. set(gca, 'xtick', unique(Xtick))
  93. Xlim = [min(Xtick), max(Xtick)];
  94. xlim(Xlim);
  95. else
  96. if islogical(Xtick) == false
  97. error('''Xtick'' must be given as a vector in increasing order')
  98. end
  99. end
  100. end
  101. %% add x- and y-axis
  102. if prod(Ylim) < 0
  103. plot(Xlim, [0,0], 'k', 'LineWidth', 2)
  104. end
  105. if prod(Xlim) < 0
  106. plot([0, 0], Ylim, 'k', 'LineWidth', 2)
  107. end
  108. ylim(Ylim);
  109. grid on;
  110. try
  111. % improvement of axes, maybe only for new versions of MATLAB?
  112. ax = gca;
  113. ax.Layer = 'top';
  114. catch
  115. warning('ax.Layer = ''top'' does not work in your enviroment, axes are not in top layer now')
  116. end

结果图:

(3)图形堆叠绘制

将相同时间间隔内的(相似的)信号堆叠到一个图形中,但复制和移位了x轴。所有子图形都使用相同的标签,不同的图形通过将背景从白色切换到灰色,然后再切换回白色来在视觉上分开。这种可视化增加了非常相似信号的可读性,特别推荐在没有彩色印刷的文章中表示/比较数据。

  1. t = 1:.1:10; y = bsxfun(@plus,2*sin(t),randn(4,numel(t))/10);
  2. y(3,20:30) = 3.1; y(1,1:15) = NaN
  3. legendcell = {'data 1','signal 2','inst. 3','set 4'}
  4. figure; plotmulti(t, y ,legendcell);
  5. figure; plotmulti(t,y,legendcell,[-3,3],[-2:.5:2],[0:1:10],'4 data sets',{'k','r','b'});

plotmulti.m函数:

  1. function handle = plotmulti(time, data,legendcell, ylimits, yticks, xticks,titleStr,color)
  2. % handle = plotmulti(time, data,legendcell, ylimits, yticks, xticks,titleStr,color)
  3. %
  4. % PLOTMULTI visualizes several one-dimensional data sets within the same time
  5. % interval in one figure and with repeated y-axes. A possible application is the
  6. % comparison of several instruments in one location.
  7. %
  8. % For readablitity, only 12 data sets are allowed.
  9. %
  10. % IN:
  11. % time: ..........argument/time [Nx1]
  12. % data:......... data set/observations [NxM]
  13. % legendcell ... legend per data set as a cell {cell}[Mx1]
  14. % ylimits:...... maximum/minimum of y-axis (equal for all sets) [2x1]
  15. % yticks:....... labels of y-axis [nx1]
  16. % xticks:....... labels of x-axis [mx1]
  17. % titleStr:..... title of the complete figure ['string']
  18. % color:........ set the color, e.g. color = {'r','b'} for red/blue signals [cell]
  19. %
  20. % OUT:
  21. % handle:........ handle of the graphics for further improvement
  22. %
  23. % See also: GRAYPATCH
  24. %
  25. % sub-routines:
  26. % * --
  27. %
  28. % REMARKS:
  29. % * The function uses the command SUBPLOT already. The application of
  30. % PLOTMULTI within another subplot might cause unexpected behaviour.
  31. % * If the vector COLOR has less entries, than the DATA matrix, then
  32. % color will be repeat
  33. %
  34. % -------------------------------------------------------------------------
  35. % project: visBundle
  36. % -------------------------------------------------------------------------
  37. % authors:
  38. % Markus ANTONI (MA), GI, Uni Stuttgart
  39. % -------------------------------------------------------------------------
  40. % revision history:
  41. % 2021-05-04: MA, new order of input & legend per data set is required
  42. % unified help text in VISBUNDLE
  43. % 2018-01-29: MA, integration into VISBUNDLE
  44. % 2018-01-24: MA, initial version
  45. % -------------------------------------------------------------------------
  46. % license:
  47. % This program is free software; you can redistribute it and/or modify
  48. % it under the terms of the GNU General Public License as published by
  49. % the Free Software Foundation; either version 3 of the License, or
  50. % (at your option) any later version.
  51. %
  52. % This program is distributed in the hope that it will be useful, but
  53. % WITHOUT ANY WARRANTY; without even the implied warranty of
  54. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  55. % GNU General Public License for more details.
  56. %
  57. % You should have received a copy of the GNU General Public License
  58. % along with Octave; see the file COPYING.
  59. % If not, see <http://www.gnu.org/licenses/>.
  60. % -------------------------------------------------------------------------
  61. %% checking argument 1,2,3
  62. narginchk(3,8)
  63. if ~ismatrix(data), error('''data'' must be a matrix'); end
  64. if ~isvector(time), error('''time'' must be a vector'); end
  65. if ~iscell(legendcell)
  66. warning('order of arguments is changed now, please check help text')
  67. error('''legendcell'' must be a cell array');
  68. end
  69. %% default settings for argument 4...8
  70. if nargin < 6, warning('''PLOTMULTI'': arguments 4,5 and 6 will improve the Figure'); end
  71. if nargin < 4, ylimits = 1.2*([min(data(:)), max(data(:))]); end
  72. if nargin < 5, yticks = ([min(data(:)), max(data(:))]); end
  73. if nargin < 6, xticks = time(1:20:end); end
  74. if nargin < 7, titleStr = 'Multiple data sets'; end
  75. if nargin < 8, color = {'k'}; end
  76. if ~iscell(color)
  77. color = {'r','b','k','g','r:','b:','k:','g:'};
  78. end
  79. if ~ischar(titleStr)
  80. titleStr = 'Multiple data sets';
  81. end
  82. % dimension of time and data
  83. time = time(:);
  84. time_anz = numel(time);
  85. [row,col] = size(data);
  86. if ismember(time_anz, [row,col]) == 0
  87. error('data set must have the same length as ''time''')
  88. end
  89. if row ~= time_anz
  90. data = data';
  91. col = row;
  92. end
  93. if col > 12
  94. error('The figures will be too small. Please split the data set')
  95. end
  96. try
  97. legendcell{col};
  98. catch
  99. error('''legendcell'' has not enough entries')
  100. end
  101. %% checking limits and labels
  102. switch numel(ylimits)
  103. case 2
  104. % everything ok
  105. case 1
  106. ylimits = [-ylimits,ylimits];
  107. otherwise
  108. error('interval ''ylimits'' must be a vector [2x1]')
  109. end
  110. xlimits = [min(time),max(time)];
  111. if isvector(xticks) == false && numel(xticks) == 1
  112. error('argument ''xticks'' must be a vector')
  113. end
  114. if isvector(yticks) == false
  115. error('argument ''yticks'' must be a vector')
  116. end
  117. xticks = unique(xticks);
  118. yticks = unique(yticks);
  119. xtickrm = xticks(2:end-1);
  120. %% plot several overlapping subplots
  121. height = 0.9/(col+1);
  122. iter = 1;
  123. iterMax = length(color);
  124. for ii = col:-1:1
  125. subplot('Position',[0.1,ii*height,0.8,height])
  126. handle(ii) = plot(time,data(:,ii),color{iter});
  127. ylim(ylimits)
  128. xlim(xlimits)
  129. set(gca,'YTick',yticks)
  130. % x-ticks for all, and for the lowest figure:
  131. if ii > 1
  132. set(gca,'XTick',xtickrm)
  133. else
  134. set(gca,'XTick',xticks)
  135. end
  136. if ii == col
  137. title(titleStr)
  138. end
  139. % try the given legends ...
  140. try
  141. legend(legendcell{ii} )
  142. catch
  143. end
  144. % gray patches for every 2nd subplot
  145. if rem(ii,2) == 1
  146. set(gca,'Color',[0.94 0.94 0.94])
  147. end
  148. % if less colors then data are given, the color repeats:
  149. iter = iter+1;
  150. if iter > iterMax
  151. iter = 1;
  152. end
  153. end

结果图:

参考资料:

  1. 1)https://www.gis.uni-stuttgart.de/en/research/downloads/visbundle/
  2. 2)The toolbox VISBUNDLE (version #/date #) was developed by N. Sneeuw, M. Weigelt,M. Roth, M. Antoni, M. Tourian et. al. and its latest version is provided via download from the Institute of Geodesy (GIS), University of Stuttgart

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/362758
推荐阅读
相关标签
  

闽ICP备14008679号