折线图

Axes3D.plot(xs,ys,*args,**kwargs)

Argument

Description

xs, ys

x, y coordinates of vertices

zs

z value(s), either one for all points or one for each point.

zdir

Which direction to use as z (‘x', ‘y' or ‘z') when plotting a 2D set.

import matplotlib as mpl

from mpl_toolkits.mplot3d import Axes3D

import numpy as np

import matplotlib.pyplot as plt

mpl.rcParams['legend.fontsize'] = 10

fig = plt.figure()

ax = fig.gca(projection='3d')

theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)

z = np.linspace(-2, 2, 100)

r = z ** 2 + 1

x = r * np.sin(theta)

y = r * np.cos(theta)

ax.plot(x, y, z, label='parametric curve')

ax.legend()

plt.show()

散点图

Axes3D.scatter(xs,ys,zs=0,zdir='z',s=20,c=None,depthshade=True,*args,**kwargs)

Argument

Description

xs, ys

Positions of data points.

zs

Either an array of the same length as xs and ys or a single value to place all points in the same plane. Default is 0.

zdir

Which direction to use as z (‘x', ‘y' or ‘z') when plotting a 2D set.

s

Size in points^2. It is a scalar or an array of the same length as x and y.

c

A color. c can be a single color format string, or a sequence of color specifications of length N, or a sequence of N numbers to be mapped to colors using the cmap and norm specified via kwargs (see below). Note that c should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. c can be a 2-D array in which the rows are RGB or RGBA, however, including the case of a single row to specify the same color for all points.

depthshade

Whether or not to shade the scatter markers to give the appearance of depth. Default is True.

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

import numpy as np

def randrange(n, vmin, vmax):

'''

Helper function to make an array of random numbers having shape (n, )

with each number distributed Uniform(vmin, vmax).

'''

return (vmax - vmin) * np.random.rand(n) + vmin

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

n = 100

# For each set of style and range settings, plot n random points in the box

# defined by x in [23, 32], y in [0, 100], z in [zlow, zhigh].

for c, m, zlow, zhigh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:

xs = randrange(n, 23, 32)

ys = randrange(n, 0, 100)

zs = randrange(n, zlow, zhigh)

ax.scatter(xs, ys, zs, c=c, marker=m)

ax.set_xlabel('X Label')

ax.set_ylabel('Y Label')

ax.set_zlabel('Z Label')

plt.show()

线框图

Axes3D.plot_wireframe(X,Y,Z,*args,**kwargs)

Argument

Description

X, Y,

Data values as 2D arrays

Z

rstride

Array row stride (step size), defaults to 1

cstride

Array column stride (step size), defaults to 1

rcount

Use at most this many rows, defaults to 50

ccount

Use at most this many columns, defaults to 50

from mpl_toolkits.mplot3d import axes3d

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

# Grab some test data.

X, Y, Z = axes3d.get_test_data(0.05)

# Plot a basic wireframe.

ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

plt.show()

表面图

Axes3D.plot_surface(X,Y,Z,*args,**kwargs)

Argument

Description

X, Y, Z

Data values as 2D arrays

rstride

Array row stride (step size)

cstride

Array column stride (step size)

rcount

Use at most this many rows, defaults to 50

ccount

Use at most this many columns, defaults to 50

color

Color of the surface patches

cmap

A colormap for the surface patches.

facecolors

Face colors for the individual patches

norm

An instance of Normalize to map values to colors

vmin

Minimum value to map

vmax

Maximum value to map

shade

Whether to shade the facecolors

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

from matplotlib import cm

from matplotlib.ticker import LinearLocator, FormatStrFormatter

import numpy as np

fig = plt.figure()

ax = fig.gca(projection='3d')

# Make data.

X = np.arange(-5, 5, 0.25)

Y = np.arange(-5, 5, 0.25)

X, Y = np.meshgrid(X, Y)

R = np.sqrt(X ** 2 + Y ** 2)

Z = np.sin(R)

# Plot the surface.

surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,

linewidth=0, antialiased=False)

# Customize the z axis.

ax.set_zlim(-1.01, 1.01)

ax.zaxis.set_major_locator(LinearLocator(10))

ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

# Add a color bar which maps values to colors.

fig.colorbar(surf, shrink=0.5, aspect=5)

plt.show()

柱状图

Axes3D.bar(left,height,zs=0,zdir='z',*args,**kwargs)

Argument

Description

left

The x coordinates of the left sides of the bars.

height

The height of the bars.

zs

Z coordinate of bars, if one value is specified they will all be placed at the same z.

zdir

Which direction to use as z (‘x', ‘y' or ‘z') when plotting a 2D set.

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):

xs = np.arange(20)

ys = np.random.rand(20)

# You can provide either a single color or an array. To demonstrate this,

# the first bar of each set will be colored cyan.

cs = [c] * len(xs)

cs[0] = 'c'

ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')

plt.show()

箭头图

Axes3D.quiver(*args,**kwargs)

Arguments:

X, Y, Z:

The x, y and z coordinates of the arrow locations (default is tail of arrow; see pivot kwarg)

U, V, W:

The x, y and z components of the arrow vectors

from mpl_toolkits.mplot3d import axes3d

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

ax = fig.gca(projection='3d')

# Make the grid

x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2),

np.arange(-0.8, 1, 0.2),

np.arange(-0.8, 1, 0.8))

# Make the direction data for the arrows

u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)

v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)

w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *

np.sin(np.pi * z))

ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True)

plt.show()

2D转3D图

from mpl_toolkits.mplot3d import Axes3D

import numpy as np

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.gca(projection='3d')

# Plot a sin curve using the x and y axes.

x = np.linspace(0, 1, 100)

y = np.sin(x * 2 * np.pi) / 2 + 0.5

ax.plot(x, y, zs=0, zdir='z', label='curve in (x,y)')

# Plot scatterplot data (20 2D points per colour) on the x and z axes.

colors = ('r', 'g', 'b', 'k')

x = np.random.sample(20 * len(colors))

y = np.random.sample(20 * len(colors))

labels = np.random.randint(3, size=80)

# By using zdir='y', the y value of these points is fixed to the zs value 0

# and the (x,y) points are plotted on the x and z axes.

ax.scatter(x, y, zs=0, zdir='y', c=labels, label='points in (x,z)')

# Make legend, set axes limits and labels

ax.legend()

ax.set_xlim(0, 1)

ax.set_ylim(0, 1)

ax.set_zlim(0, 1)

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')

# Customize the view angle so it's easier to see that the scatter points lie

# on the plane y=0

ax.view_init(elev=20., azim=-35)

plt.show()

文本图

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.gca(projection='3d')

# Demo 1: zdir

zdirs = (None, 'x', 'y', 'z', (1, 1, 0), (1, 1, 1))

xs = (1, 4, 4, 9, 4, 1)

ys = (2, 5, 8, 10, 1, 2)

zs = (10, 3, 8, 9, 1, 8)

for zdir, x, y, z in zip(zdirs, xs, ys, zs):

label = '(%d, %d, %d), dir=%s' % (x, y, z, zdir)

ax.text(x, y, z, label, zdir)

# Demo 2: color

ax.text(9, 0, 0, "red", color='red')

# Demo 3: text2D

# Placement 0, 0 would be the bottom left, 1, 1 would be the top right.

ax.text2D(0.05, 0.95, "2D Text", transform=ax.transAxes)

# Tweaking display region and labels

ax.set_xlim(0, 10)

ax.set_ylim(0, 10)

ax.set_zlim(0, 10)

ax.set_xlabel('X axis')

ax.set_ylabel('Y axis')

ax.set_zlabel('Z axis')

plt.show()

3D拼图

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d.axes3d import Axes3D, get_test_data

from matplotlib import cm

import numpy as np

# set up a figure twice as wide as it is tall

fig = plt.figure(figsize=plt.figaspect(0.5))

# ===============

# First subplot

# ===============

# set up the axes for the first plot

ax = fig.add_subplot(1, 2, 1, projection='3d')

# plot a 3D surface like in the example mplot3d/surface3d_demo

X = np.arange(-5, 5, 0.25)

Y = np.arange(-5, 5, 0.25)

X, Y = np.meshgrid(X, Y)

R = np.sqrt(X ** 2 + Y ** 2)

Z = np.sin(R)

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,

linewidth=0, antialiased=False)

ax.set_zlim(-1.01, 1.01)

fig.colorbar(surf, shrink=0.5, aspect=10)

# ===============

# Second subplot

# ===============

# set up the axes for the second plot

ax = fig.add_subplot(1, 2, 2, projection='3d')

# plot a 3D wireframe like in the example mplot3d/wire3d_demo

X, Y, Z = get_test_data(0.05)

ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

plt.show()

到此这篇关于Matplotlib.pyplot 三维绘图的实现示例的文章就介绍到这了,更多相关Matplotlib.pyplot 三维绘图内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

python 三维折线图_Matplotlib.pyplot 三维绘图的实现示例相关推荐

  1. python三维数据图_matplotlib中三维数据的热图

    我想用我的三维数据生成一张热图.在 我已经能够用这些数据绘制出trisurf.在 有人能帮我制作热图吗?我看到了在线教程,但是它们对3D来说都很复杂,我在这个网站上找到了一个在matplotlib中生 ...

  2. python_pyecharts画三维折线图

    1.摘要 本文主要讲解:使用python中的pyecharts画三维折线图 主要思路: 将数据处理成[[x-],[y-],[z-]]的形式 使用Line3D函数渲染 2.数据介绍 数据为简单的三维数据 ...

  3. origin Pro 9.0画多条三维折线图(此处以两条为例)

    origin Pro 9.0画多条三维折线图(此处以两条为例) 首先,建立两个New workbook,将需要的绘制的图分别放在book1 book2-如下图 选中book1 中的三维数据,操作如下图 ...

  4. Matlab三维折线图绘制–surf 函数的使用

    Matlab三维折线图绘制–surf 函数的使用   最近在写毕业论文,整理数据需要绘制一个简单的三维图,简单做个分享! 先上结果图: 最后附上代码: clc,clear,close all; % f ...

  5. 可视化例子(11)——ECharts line3D制作三维折线图

    因工作需要,制作了三维折线图,可以看到三个变量的变化.其效果如下图所示: 其中遇到了一个很大的问题,line3D 无法出现标签(查看了所有配置项,均没有该配置,这应该是 ECharts 的一个 bug ...

  6. python 绘制折线图-怎样用python绘制折线图

    今天教大家用python绘制一些线性图案,需要的朋友可以借鉴参考一下. 画最简单的直线图 代码如下:import numpy as np import matplotlib.pyplot as plt ...

  7. 【Python】用Python绘制折线图(插值法平滑曲线)

    目录 利用绘制图表:​​​​​​matplotlib官网 1. 小试牛刀--柱状图 1.1 matplotlib库默认英文字体 2. 折线图绘制 2.1 读取exal方法 2.1.1  数据处理常用库 ...

  8. 修改python plot折线图的坐标轴刻度

    修改python plot折线图的坐标轴刻度,这里修改为整数: 代码如下: from matplotlib import pyplot as plt import matplotlib.ticker ...

  9. python简单代码画曲线图教程-Python绘制折线图和散点图的详细方法介绍(代码示例)...

    本篇文章给大家带来的内容是关于Python绘制折线图和散点图的详细方法介绍(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 1.绘制折线图和散点图要用到matplotlib ...

最新文章

  1. Matlab基本函数-conj函数
  2. HarmonyOS之在工程中导入Sample工程和添加Module
  3. mysql主主备份及集群
  4. surfaceView中的线程问题
  5. 【2018.5.19】模拟赛之三-ssl2434 取数【搜索,卡常或记忆化搜索】
  6. c++中vecto容器r常使用的相关函数
  7. gdb vscode 不进入断点_VScode配置MASM32运行环境(断点/运行/debug/配合emu8086(非DOSBox))...
  8. LeetCode-----旋转数组的最小数字
  9. ROBOTS.TXT在SEO优化中的运用(ROBOTS.TXT SEO优化实战)
  10. 搭建Discuz论坛的两种方式
  11. 算法竞赛入门经典习题
  12. HTML基础代码大全
  13. 简单工厂模式与策略模式
  14. php求圆柱体积,认识圆柱体a href=http://ruiwen.com/friend/list.php(教师中心专稿)/a -- 小学数学教学资源网...
  15. 非常全面的前端协作规范
  16. 老年机打不出电话拨号失败服务器无响应,老年机为什么打不出去电话
  17. 阿里云服务器nginx配置ssl步骤htts
  18. 新会计准则——新增固定资产可以当月计提折旧
  19. excel 计算机职称,职称计算机2017年Excel知识点:工作表的编辑
  20. img标签前面加冒号:src和src的区别

热门文章

  1. 【UE4】一个实现Web穿透,用HTML开发UI的方式——WebUI的用法
  2. 六十八个超级经典小故事(做人、处事、经商之道)
  3. 2022-2028全球与中国环氧模塑料市场现状及未来发展趋势
  4. Numpy(附Matplotlib)基础核心内容
  5. 网站页面性能优化的34条守则
  6. 《道德情操论》与《中庸》--《可以量化的经济学》
  7. numpy.ndarray.transpose
  8. 在OpenCV里图像数据与一维数组转换
  9. 第五讲 一元函数微分学的几何应用
  10. 挣脱PC枷锁,争当互联网主人