PY_matplotlib

1.二维平面函数绘图

1.基础版(y=x^2)
#抛物线
import numpy as np
import matplotlib.pyplot as plt   #导入matplotlib库

x = np.arange(-100,100,0.1)  #x步长为0.1
y = x**2

plt.xlim(-12,12)  #设置x、y坐标轴的范围
plt.ylim(0, 100)

plt.plot(x,y)

plt.show()

在这里插入图片描述

2.添加画布和坐标轴箭头

import numpy as np
import matplotlib.pyplot as plt   #导入matplotlib库
import mpl_toolkits.axisartist as axisartist



fig = plt.figure(figsize=(8, 8))    #创建画布
ax = axisartist.Subplot(fig, 111)   #使用axisartist.Subplot方法创建一个绘图区对象ax
fig.add_axes(ax)    #将绘图区对象添加到画布中


ax.axis[:].set_visible(False)   #通过set_visible方法设置绘图区所有坐标轴隐藏

ax.axis["x"] = ax.new_floating_axis(0,0)    #ax.new_floating_axis代表添加新的坐标轴
ax.axis["x"].set_axisline_style("->", size = 1.0)   #给x坐标轴加上箭头

ax.axis["y"] = ax.new_floating_axis(1,0)    #添加y坐标轴,且加上箭头
ax.axis["y"].set_axisline_style("-|>", size = 1.0)

ax.axis["x"].set_axis_direction("top")  #设置x、y轴上刻度显示方向
ax.axis["y"].set_axis_direction("right")

x = np.arange(-100,100,0.1)  #x步长为0.1
y = x**2
plt.xlim(-12,12)  #设置x、y坐标轴的范围
plt.ylim(0, 100)
plt.plot(x,y)
plt.show()

2.三维函数绘图

参考链接:https://blog.csdn.net/Mr_Cat123/article/details/100054757
3d绘图汇总:http://c.biancheng.net/matplotlib/3d-plot.html

figure语法说明:
figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)

  • num:图像编号或名称,数字为编号 ,字符串为名称
  • figsize:指定figure的宽和高,单位为英寸; dpi参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为801英寸等于2.5cm,A4纸是 21*30cm的纸张 facecolor:背景颜色 edgecolor:边框颜色
  • frameon:是否显示边框

plt、fig、axes、axis的含义:https://blog.csdn.net/qq_38048756/article/details/117741677

1.基础版(z = x^2 + y^2)
import numpy as np
import matplotlib.pyplot as plt


x = np.arange(-10,10,0.2)
y = np.arange(-10,10,0.2)
z = np.power(x,2)+np.power(y,2)  #z = x**2 + y**2

fig = plt.figure()  #生成一个figure画布
ax = plt.axes(projection='3d') #创建3d绘图区域
ax.plot(x,y,z)
plt.show()

在这里插入图片描述

3.建立几何模型

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d

# print("请输入a1:")
a1 = 1
# print("请输入b1:")
b1 = 2

u = np.linspace(0, np.pi, 256, endpoint=True)
v = np.linspace(0, 2 * np.pi, 256, endpoint=True)
u, v = np.meshgrid(u, v)


def x(u, v):
    return a1 * np.sin(u) * np.cos(v)

def y(u, v):
    return a1 * np.sin(u) * np.sin(v)

def z(u):
    return b1 * np.cos(u)


# x = a1*np.sin(u)*np.cos(v)
# y = a1*np.sin(u)*np.sin(v)
# z = b1*np.cos(u)

x = x(u, v)
y = y(u, v)
z = z(u)

fig = plt.figure()  # 生成一个figure画布
ax = plt.axes(projection='3d')  # 创建3d绘图区域
plt.gca().set_box_aspect((a1, a1, b1))  # 当x、y、z轴范围之比为3:5:2时。
ax.plot_wireframe(x, y, z)
ax.set_title('tuoqiu')
plt.xlabel('x')
plt.ylabel('y')
plt.show()

https://vimsky.com/examples/usage/python-scipy.interpolate.griddata.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
E:\visualization\analysis\1.py:80: MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later. plt.show() C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 21508 (\N{CJK UNIFIED IDEOGRAPH-5404}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 20010 (\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 26376 (\N{CJK UNIFIED IDEOGRAPH-6708}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 20221 (\N{CJK UNIFIED IDEOGRAPH-4EFD}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 30340 (\N{CJK UNIFIED IDEOGRAPH-7684}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 38144 (\N{CJK UNIFIED IDEOGRAPH-9500}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 21806 (\N{CJK UNIFIED IDEOGRAPH-552E}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 24773 (\N{CJK UNIFIED IDEOGRAPH-60C5}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 20917 (\N{CJK UNIFIED IDEOGRAPH-51B5}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 36135 (\N{CJK UNIFIED IDEOGRAPH-8D27}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 21697 (\N{CJK UNIFIED IDEOGRAPH-54C1}) missing from current font. FigureCanvasAgg.draw(self) Process finished with exit code 0
05-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值