python - python matplotlib - How to plot 3+1 dimension data?
问题描述
I've got an array of 4 dimensions. The first 3 dimension, x, y, z
are categorical integer variables with value range [-3,3]. The combination of them are unique, i.e. no same x, y, z
values in 2 rows. The last dimension value
, is a continuous positive float variable. For example:
x y z value
0 0 0 1.0
1 0 1 2.5
-1 1 -1 0.3
3 2 1 0.06
I'd like to visualise the array with matplotlib in python. The plot will be a 3D plot with x, y, z
as axes, and each datapoint will be a sphere, the radius of the sphere will be value
. I have only done this in Tableau previously. How can I do this with python?
P.S. In the case that value
is not necessarily positive, I'd love to know how to use color as indicator of sign of value
in addition to above question. Though I suppose an argument of color=sign(value)
will do the work.
解决方案
我已经根据@tnknepp 在Plotting 4d-data中的回答对其进行了整理
代码很简单:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='3d')
sp = ax.scatter(x,y,z, s=value, c=color)
plt.colorbar(sp)
其中s
是气泡的大小,c
是颜色。
推荐阅读
- javascript - Stencil js - requestAnimationFrame 不会出现在所有组件中
- c++ - 遇到换行符时使用 getline 退出循环
- php - 如何组合两个(或更多)preg_replace - PHP
- python - 如何“去串化”腌制对象?
- sql - 数据库表作为多个实例的作业队列
- amazon-web-services - AWS EKS 节点创建失败
- regex - 正则表达式 PowerShell:如果逗号之间没有值,则将每个逗号替换为 [blank]
- reactjs - 如果页面不存在,如何在静态反应应用程序中发送 http 状态代码 404?
- java - 泽西客户端 3.x 在 Android 上
- xcode - 带有 Pod 的 Xcode:在框架标头中双引号包含“ph.b”