简体   繁体   English

Matlab:如何在(x,y,z)坐标中绘制堆叠的3D条形图?

[英]Matlab: how to plot a stacked 3D bar plot in (x,y,z)-coordinates?

I'd like to plot a stacked 3D bar in three-dimensional coordinates, ie, given x, and y, z is a stacked 3D bar. 我想在三维坐标中绘制堆叠的3D条形,即给定x和y,z是堆叠的3D条形。 It seems like Matlab only supports such plot in two-dimensional coordinates. Matlab似乎仅支持二维坐标中的这种绘图。

for example, how to plot such a stacked 3D bar in (x,y,z) space using the following data sets? 例如,如何使用以下数据集在(x,y,z)空间中绘制这种堆叠的3D条形图?

    x, y, z
    1, 2, (3+4)
    1, 1, (5+6)
    2, 1, (1+1)

Thanks! 谢谢!

You have two general approaches you can take... 您可以采用两种一般方法...

  1. Plot your own bars (ie cuboids): You can create a function that takes the sets of values and plots the cuboid surfaces at those points. 绘制自己的条形图(即长方体):您可以创建一个函数,该函数采用一组值并在这些点处绘制长方体表面。 There are a few ways to create basic 3D cubes, which are covered in this question and this MATLAB Newsgroup thread . 有几种创建基本3D多维数据集的方法, 此问题该MATLAB Newsgroup线程都介绍了这些方法 You would just have to scale, shift, and recolor the cube surfaces accordingly. 您只需要相应地缩放,移动和重新着色立方体表面即可。 If this seems a daunting task, then... 如果这似乎是一项艰巨的任务,那么...

  2. Make multiple BAR3 plots, modifying each accordingly: This question covers how to make a grid of stacked bar plots. 制作多个BAR3图,并相应地进行修改: 这个问题涵盖了如何制作一个堆叠的条形图网格。 In your case, you probably wouldn't want a full grid, but sparse stacked bars scattered at different coordinates in a region. 在您的情况下,您可能不希望有一个完整的网格,而是将稀疏堆积的条形散布在一个区域的不同坐标上。 In this case, you could format your data to work with the solution in the above question by creating 2-D sets of data for z , filled with zeroes where you don't want any bars. 在这种情况下,您可以通过为z创建2D数据集(在不需要任何小节的地方填充零)来格式化数据以与上述问题中的解决方案一起使用。 Then you can remove the unwanted zero-value bars at each step using the solutions from this question . 然后,您可以使用此问题的解决方案在每个步骤中删除不需要的零值条。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM