条形图(o 图)3D

发布于 2024-07-19 02:26:17 字数 1086 浏览 9 评论 0原文

我需要以各种形式绘制一些数据。 目前我正在使用 Matplotlib 并且我对能够绘制的图相当满意生产。

这个问题是关于如何绘制最后一个。 数据类似于“距离表”,比如这个< /a> (更大,我的表是 128x128,每个元素仍然有 3 个或更多数字)。

现在,我的数据比距离表更好地“结构化”(我的数据不会像按字母顺序排序的距离表那样“随机”变化),因此是 3D 条形图,或者其中 3 个,就很完美了。 我的理解是 Matplotlib 中缺少这样的图表。

我可以使用像 这些 这样的(彩色)Countor3d 或像 imshow 这样的 2D 东西,但是它并不能很好地代表数据的内容(数据仅在我的 128 点中有意义,两点之间没有任何内容)。 在我看来,条形的高度比颜色更易读。

因此问题是:

  1. 是否可以在 Matplotlib 中创建 3D 条形图? 应该清楚的是,我的意思是使用 2D 域,而不仅仅是出于美观目的带有“假”3D 渲染的 2D 条形图,
  2. 如果上一个问题的答案是否定的,那么是否有其他库能够做到这一点? 我非常喜欢基于 Python 的东西,但我也同意其他 Linux 友好的可能性,
  3. 如果上一个问题的答案是否定的,那么您对如何显示该数据有什么建议吗? 例如,创建一个包含值的表格,叠加到 imshow 或其他彩色方式?

I need to plot some data in various forms. Currently I'm using Matplotlib and I'm fairly happy with the plots I'm able to produce.

This question is on how to plot the last one. The data is similar to the "distance table", like this (just bigger, my table is 128x128 and still have 3 or more number per element).

Now, my data is much better "structured" than a distance table (my data doesn't varies "randomly" like in a alphabetically sorted distance table), thus a 3D barchart, or maybe 3 of them, would be perfect. My understanding is that such a chart is missing in Matplotlib.

I could use a (colored) Countor3d like these or something in 2D like imshow, but it isn't really well representative of what the data is (the data has meaning just in my 128 points, there isn't anything between two points). And the height of bars is more readable than color, IMO.

Thus the questions:

  1. is it possible to create 3D barchart in Matplotlib? It should be clear that I mean with a 2D domain, not just a 2D barchart with a "fake" 3D rendering for aesthetics purposes
  2. if the answer to the previous question is no, then is there some other library able to do that? I strongly prefer something Python-based, but I'm OK with other Linux-friendly possibilities
  3. if the answer to the previous question is no, then do you have any suggestions on how to show that data? E.g. create a table with the values, superimposed to the imshow or other colored way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

箜明 2024-07-26 02:26:17

一段时间以来,matplotlib 没有 3D 支持,但最近又重新添加了 。 您将需要使用 svn 版本,因为此后尚未发布任何版本,并且文档有点稀疏(请参阅示例/mplot3d/demo.py)。 我不知道 mplot3d 是否支持真正的 3D 条形图,但其中一个演示看起来有点像可以扩展到类似的东西。

编辑:演示的源代码位于示例中,但由于某种原因结果不是。 我的意思是 test_polys 函数,它的样子如下:

示例图 http:// www.iki.fi/jks/tmp/poly3d.png

test_bar2D 函数会更好,但它在演示中被注释掉,因为它会导致当前 svn 版本出现错误。 可能是一些微不足道的问题,或者是更难解决的问题。

For some time now, matplotlib had no 3D support, but it has been added back recently. You will need to use the svn version, since no release has been made since, and the documentation is a little sparse (see examples/mplot3d/demo.py). I don't know if mplot3d supports real 3D bar charts, but one of the demos looks a little like it could be extended to something like that.

Edit: The source code for the demo is in the examples but for some reason the result is not. I mean the test_polys function, and here's how it looks like:

example figure http://www.iki.fi/jks/tmp/poly3d.png

The test_bar2D function would be even better, but it's commented out in the demo as it causes an error with the current svn version. Might be some trivial problem, or something that's harder to fix.

森末i 2024-07-26 02:26:17

MyavaVi2 可以使 3D 条形图(向下滚动一点)。 一旦您拥有 MayaVi/VTK/ETS/etc 。 安装完毕后,一切工作都很顺利,但安装起来可能需要一些工作。 Ubuntu 已经打包了所有这些,但它们是我所知道的唯一这样做的 Linux 发行版。

MyavaVi2 can make 3D barcharts (scroll down a bit). Once you have MayaVi/VTK/ETS/etc. installed it all works beautifully, but it can be some work getting it all installed. Ubuntu has all of it packaged, but they're the only Linux distribution I know that does.

娇纵 2024-07-26 02:26:17

另一种可能性是 Gnuplot,它可以绘制某种 伪 3D 条形图gnuplot.py 允许从 Python 连接到 Gnuplot。 不过,我自己还没有尝试过。

One more possibility is Gnuplot, which can draw some kind of pseudo 3D bar charts, and gnuplot.py allows interfacing to Gnuplot from Python. I have not tried it myself, though.

—━☆沉默づ 2024-07-26 02:26:17

这是我使用 matplotlib 编写的简单 Bar-3d 代码。

import mpl_toolkits
from mpl_toolkits.mplot3d import Axes3D   
import matplotlib.pyplot as plt
%matplotlib inline

## The value you want to plot 
zval=[0.020752244,0.078514652,0.170302899,0.29543857,0.45358061,0.021255922,0.079022499,\
  0.171294169,0.29749654,0.457114286,0.020009631,0.073154019,0.158043498,0.273889264,0.419618287]    

fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(111,projection='3d')
col=["#ccebc5","#b3cde3","#fbb4ae"]*5
xpos=[1,2,3]*5
ypos=range(1,6,1)*5
zpos=[0]*15
dx=[0.4]*15
dy=[0.5]*15
dz=zval

for i in range(0,15,1):
     ax.bar3d(ypos[i], xpos[i], zpos[i], dx[i], dy[i], dz[i],     
color=col[i],alpha=0.75)

ax.view_init(azim=120)
plt.show()      

http://i8.tietuku.com/ea79b55837914ab2.png

This is my code for a simple Bar-3d using matplotlib.

import mpl_toolkits
from mpl_toolkits.mplot3d import Axes3D   
import matplotlib.pyplot as plt
%matplotlib inline

## The value you want to plot 
zval=[0.020752244,0.078514652,0.170302899,0.29543857,0.45358061,0.021255922,0.079022499,\
  0.171294169,0.29749654,0.457114286,0.020009631,0.073154019,0.158043498,0.273889264,0.419618287]    

fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(111,projection='3d')
col=["#ccebc5","#b3cde3","#fbb4ae"]*5
xpos=[1,2,3]*5
ypos=range(1,6,1)*5
zpos=[0]*15
dx=[0.4]*15
dy=[0.5]*15
dz=zval

for i in range(0,15,1):
     ax.bar3d(ypos[i], xpos[i], zpos[i], dx[i], dy[i], dz[i],     
color=col[i],alpha=0.75)

ax.view_init(azim=120)
plt.show()      

http://i8.tietuku.com/ea79b55837914ab2.png

薄凉少年不暖心 2024-07-26 02:26:17

您可以查看图表总监:

http://www.advsofteng.com

它有各种各样的图表和图形,并且有一个很好的 Python (以及其他几种语言)API。

有两个版本:免费版本在生成的图像上添加了简介,而
付费版本的价格相当合理。

这是看起来更有趣的 3D 堆叠条形图之一:

样本图
(来源:advsofteng.com

You might check out Chart Director:

http://www.advsofteng.com

It has a pretty wide variety of charts and graphs and has a nice Python (and several other languages) API.

There are two editions: The free version puts a blurb on the generated image, and the
pay version is pretty reasonably priced.

Here's one of the more interesting looking 3d stacked bar charts:

sample graph
(source: advsofteng.com)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文