matplot绘制三维图
作者:互联网
def show_3d(data, axis=-1):
"""绘制三维"""
import matplotlib.pyplot as plt
import pandas as pd
if not isinstance(data, pd.DataFrame):
data = pd.DataFrame(data)
# 1. 创建图(绘制环境)
figure = plt.figure('3D图形', figsize=(13, 10))
# 2. 创建3D坐标系(直接创建,使用Figure中的函数创建:这里使用函数)
ax = figure.add_axes([0.1, 0.1, 0.9, 0.9], projection='3d')
colors = ['r', 'g', 'b', 'y', 'm', 'c', 'teal', 'pink', 'tan', 'k', 'gold', 'springgreen', 'orange', 'skyblue',
'aqua',
'r', 'g', 'b', 'y', 'm', 'c', 'teal', 'pink', 'tan', 'k', 'gold', 'springgreen', 'orange', 'skyblue',
'aqua',
'r', 'g', 'b', 'y', 'm', 'c', 'teal', 'pink', 'tan', 'k', 'gold', 'springgreen', 'orange', 'skyblue',
'aqua']
if axis == 0:
Iter = data.iterrows()
else:
Iter = data.iteritems()
j = 0
for k, item in Iter:
cs = colors[j]
ax.plot(range(len(item)), item, j, color=cs, zdir='y') # zdir是y,则柱状图在xz平面上
j += 1
ax.grid(b=False) # 网格线
plt.show()
给定数据,指定方向即可,0为行,1为列,默认-1
标签:matplot,pink,gold,figure,data,三维图,ax,tan,绘制 来源: https://blog.csdn.net/mutao1127877836/article/details/111260470