本文实例讲述了Python使用matplotlib绘制三维图形。分享给大家供大家参考,具体如下:
用二维泡泡图表示三维数据
泡泡的坐标2维,泡泡的大小三维,使用到的函数
plt.scatter(P[:,0], P[:,1], s=S, lw = 1.5,
edgecolors = C, facecolors='None')
其中P[:,0], P[:,1]为泡泡的坐标数据,s为泡泡的大小,lw为泡泡的边线宽度,edgecolors为边线颜色,facecolors为填充颜色
代码及注释
# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(9,6))
# 泡泡的数量
n = 50
size_min = 50
size_max = 50*50
# Ring position,rand可以产生2维数组
P = np.random.rand(n,2)
# Ring colors R,G,B,A
C = np.ones((n,4)) * (0,0,0,1)
# Alpha color channel goes from 0 (transparent) to 1 (opaque)
C[:,3] = np.linspace(0,1,n)
# Ring sizes
S = np.linspace(size_min, size_max, n)
# Scatter plot
plt.scatter(P[:,0], P[:,1], s