备案多个网站,网站降权如何恢复,免费自助建站代理,Python爬取wordpress博客目录
一、环境搭建
1.1 配置matplotlib库
1.2 配置seaborn库
1.3 配置Skimage库
二、二维图像
2.1 曲线#xff08;直线#xff09;可视化
2.2 曲线#xff08;虚线#xff09;可视化
2.3 直方图
2.4 阶梯图
三、三维图像
3.1 3D曲面图
3.2 3D散点图
3.3 3D散…目录
一、环境搭建
1.1 配置matplotlib库
1.2 配置seaborn库
1.3 配置Skimage库
二、二维图像
2.1 曲线直线可视化
2.2 曲线虚线可视化
2.3 直方图
2.4 阶梯图
三、三维图像
3.1 3D曲面图
3.2 3D散点图
3.3 3D散点图 Matplotlib库是一款功能强大且灵活的Python数据可视化软件包它支持跨平台运行能够根据NumPy ndarray数组绘制高质量的2D图像也支持部分3D图像。Matplotlib提供了类MATLAB的绘图API使得绘图过程简单直观代码清晰易懂。它广泛应用于数据分析、科学研究、报告生成以及教育与培训等领域用户可以通过它创建多样化的图表类型如折线图、柱状图、散点图等并对图表的各个元素进行高度定制化的调整。无论是简单的图表还是复杂的可视化需求Matplotlib都能提供高质量的输出。 一、环境搭建
1.1 配置matplotlib库
pip install matplotlib 安装成功展示图 1.2 配置seaborn库
pip install seaborn 安装成功展示图 1.3 配置Skimage库
pip install scikit-image 安装成功展示图 二、二维图像
2.1 曲线直线可视化
import matplotlib.pyplot as plt
import numpy as npX np.linspace(1, 15)
Y np.sin(X)
# 图像大小设置
plt.figure(figsize(10,8))
# 绘制线
plt.plot(X, Y, colorred)
plt.xlabel(X)
plt.ylabel(Y)
# 设置图像标题名
plt.title(y sin(X))
# 是否添加网格
plt.grid(True)
# 绘制图像
plt.show() 2.2 曲线虚线可视化
import matplotlib.pyplot as plt
import numpy as npX np.linspace(1, 15)
Y np.sin(X)
# 图像大小设置
plt.figure(figsize(10,8))
# 绘制线 蓝色 虚线
plt.plot(X, Y, b-.)
plt.xlabel(r$\alpha$)
plt.ylabel(r$\beta$)
# 设置图像标题名
plt.title($y\sum sin(x)$)
# 是否添加网格
plt.grid(True)
# 绘制图像
plt.show() 2.3 直方图
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
matplotlib.rcParams[axes.unicode_minus] False
import seaborn as sns
sns.set(font Kaiti, style ticks, font_scale 1.4)X np.linspace(1, 15)
Y np.sin(X)
# 图像大小设置
plt.figure(figsize(10,8))
# 生成数据
data np.random.randn(200, 1)
# 可视化
plt.hist(data, 10)
plt.xlabel(取值)
plt.ylabel(频数)
plt.title(直方)
# 绘制图像
plt.show() 2.4 阶梯图
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
from matplotlib.pyplot import xticksmatplotlib.rcParams[axes.unicode_minus] False
import seaborn as sns
sns.set(font Kaiti, style ticks, font_scale 1.4)X np.linspace(1, 15)
Y np.sin(X)
# 图像大小设置
plt.figure(figsize(10,8))
# 阶梯图设置
plt.step(X, Y, c r, label sin(x), linewidth 3)
# 添加辅助线
plt.plot(X, Y, o--, color grey, alpha 0.5)
plt.xlabel(X)
plt.ylabel(Y)
plt.title(Bar)
# 设置图例位置及大小
plt.legend(loc lower right, fontsize small)
# 设置X轴坐标系取值
xtick [0, 5, 10, 15]
xticklabels [str(x) 万 for x in xtick]
# x轴的坐标取值倾斜度为45°
plt.xticks(xtick, xticklabels, rotation 45)
# 调整水平空间距离
plt.subplots_adjust(hspace 0.5)
plt.show() 三、三维图像
3.1 3D曲面图
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
from matplotlib.pyplot import xticks
from pyparsing import alphas
matplotlib.rcParams[axes.unicode_minus] False
import seaborn as sns
sns.set(font Kaiti, style ticks, font_scale 1.4)x np.linspace(-4, 4, num 50)
y np.linspace(-4, 4, num 50)
X, Y np.meshgrid(x, y)
Z np.sin(np.sqrt(X**2 Y**2))
# 3D曲面图可视化
fig plt.figure(figsize(6, 5))
# 设置3D坐标
ax1 fig.add_subplot(1, 1, 1, projection 3d)
# 绘制曲面图, rstride行的跨度 cstride列的跨度 alpha透明度 cmap颜色
ax1.plot_surface(X, Y, Z, rstride 1, cstride 1, alpha 0.5, cmap plt.cm.coolwarm)
# 绘制z轴方向的等高线
cset ax1.contourf(X, Y, Z, zdir z, offset 1, cmap plt.cm.CMRmap)
ax1.set_xlabel(X)
ax1.set_xlim(-4, 4)
ax1.set_ylabel(Y)
ax1.set_ylim(-4, 4)
ax1.set_zlabel(Z)
ax1.set_zlim(-1, 1)
ax1.set_title(曲面图和等高线)
plt.show() 3.2 3D散点图
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
from matplotlib.pyplot import xticks
from pyparsing import alphas
matplotlib.rcParams[axes.unicode_minus] False
import seaborn as sns
sns.set(font Kaiti, style ticks, font_scale 1.4)theta np.linspace(-4 * np.pi, 4 * np.pi, 100)
x np.cos(theta)
y np.sin(theta)
z np.linspace(-2, 2, 100)
r z ** 2 1
# 在子图中绘制三维图像
fig plt.figure(figsize(10, 10))
# 将坐标系设置为3D坐标系
ax1 fig.add_subplot(1, 1, 1, projection3d)
ax1.plot(x, y, z, b-)
ax1.view_init(elev 20, azim 25)
ax1.set_title(3D曲线图)
plt.show() 3.3 3D散点图
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
from matplotlib.pyplot import xticks
from pyparsing import alphas
matplotlib.rcParams[axes.unicode_minus] False
import seaborn as sns
sns.set(font Kaiti, style ticks, font_scale 1.4)theta np.linspace(-4 * np.pi, 4 * np.pi, 100)
x np.cos(theta)
y np.sin(theta)
z np.linspace(-2, 2, 100)
r z ** 2 1
# 在子图中绘制三维图像
fig plt.figure(figsize(10, 10))
# 将坐标系设置为3D坐标系
ax1 plt.subplot(1, 1, 1, projection3d)
ax1.scatter3D(x, y, z, c r, s 20)
ax1.view_init(elev 20, azim 25)
ax1.set_title(3D散点图)
plt.show()上一篇文章Python的pandas库基础知识超详细教学-CSDN博客https://blog.csdn.net/Z0412_J0103/article/details/144849671https://blog.csdn.net/Z0412_J0103/article/details/144849671https://blog.csdn.net/Z0412_J0103/article/details/144849671下一篇文章:Python实现简单的缺失值处理超详细教程-CSDN博客https://blog.csdn.net/Z0412_J0103/article/details/144956087