Python数据可视化科技图表绘制系列教程(二)

news2025/6/9 18:02:52

目录

表格风格图

使用Seaborn函数绘图

设置图表风格

设置颜色主题

图表分面

绘图过程

使用绘图函数绘图

定义主题

分面1

分面2


【声明】:未经版权人书面许可,任何单位或个人不得以任何形式复制、发行、出租、改编、汇编、传播、展示或利用本博客的全部或部分内容,也不得在未经版权人授权的情况下将本博客用于任何商业目的。但版权人允许个人学习、研究、欣赏等非商业性用途的复制和传播。非常推荐大家学习《Python数据可视化科技图表绘制》这本书籍。

表格风格图

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as mcolors
from matplotlib.patches import Rectangle

np.random.seed(19781101)			# 固定随机种子,以便结果可复现

def plot_scatter(ax,prng,nb_samples=100):
    """绘制散点图"""
    for mu,sigma,marker in [(-.5,0.75,'o'),(0.75,1.,'s')]:
        x,y=prng.normal(loc=mu,scale=sigma,size=(2,nb_samples))
        ax.plot(x,y,ls='none',marker=marker)
    ax.set_xlabel('X-label')
    ax.set_title('Axes title')
    return ax

def plot_colored_lines(ax):
    """绘制颜色循环线条"""
    t=np.linspace(-10,10,100)
    def sigmoid(t,t0):
        return 1/(1+np.exp(-(t-t0)))
    nb_colors=len(plt.rcParams['axes.prop_cycle'])
    shifts=np.linspace(-5,5,nb_colors)
    amplitudes=np.linspace(1,1.5,nb_colors)
    for t0,a in zip(shifts,amplitudes):
        ax.plot(t,a*sigmoid(t,t0),'-')
    ax.set_xlim(-10,10)
    return ax

def plot_bar_graphs(ax,prng,min_value=5,max_value=25,nb_samples=5):
    """绘制两个并排的柱状图。"""
    x=np.arange(nb_samples)
    ya,yb=prng.randint(min_value,max_value,size=(2,nb_samples))
    width=0.25
    ax.bar(x,ya,width)
    ax.bar(x+width,yb,width,color='C2')
    ax.set_xticks(x+width,labels=['a','b','c','d','e'])
    return ax

def plot_colored_circles(ax,prng,nb_samples=15):
    """绘制彩色圆形。"""
    for sty_dict,j in zip(plt.rcParams['axes.prop_cycle'](),
						    range(nb_samples)):
        ax.add_patch(plt.Circle(prng.normal(scale=3,size=2),
						         radius=1.0,color=sty_dict['color']))
    ax.grid(visible=True)
  	# 添加标题以启用网格
    plt.title('ax.grid(True)',family='monospace',fontsize='small')
    ax.set_xlim([-4,8])
    ax.set_ylim([-5,6])
    ax.set_aspect('equal',adjustable='box')			# 绘制圆形
    return ax

def plot_image_and_patch(ax,prng,size=(20,20)):
    """绘制图像和圆形补丁。"""
    values=prng.random_sample(size=size)
    ax.imshow(values,interpolation='none')
    c=plt.Circle((5,5),radius=5,label='patch')
    ax.add_patch(c)
    # 移除刻度
    ax.set_xticks([])
    ax.set_yticks([])

def plot_histograms(ax,prng,nb_samples=10000):
    """绘制四个直方图和一个文本注释。"""
    params=((10,10),(4,12),(50,12),(6,55))
    for a,b in params:
        values=prng.beta(a,b,size=nb_samples)
        ax.hist(values,histtype="stepfilled",bins=30,
                alpha=0.8,density=True)
    # 添加小注释。
    ax.annotate('Annotation',xy=(0.25,4.25),
           xytext=(0.9,0.9),textcoords=ax.transAxes,
           va="top",ha="right",
           bbox=dict(boxstyle="round",alpha=0.2),
           arrowprops=dict(arrowstyle="->",
	               connectionstyle="angle,angleA=-95,angleB=35,rad=10"),)
    return ax

def plot_figure(style_label=""):
    """设置并绘制具有给定样式的演示图。"""
    # 在不同的图之间使用专用的RandomState实例绘制相同的“随机”值
    prng=np.random.RandomState(96917002)
    # 创建具有特定样式的图和子图
    fig,axs=plt.subplots(ncols=6,nrows=1,num=style_label,
                 figsize=(14.8,2.8),layout='constrained')

    # 添加统一的标题,标题颜色与背景颜色相匹配
    background_color=mcolors.rgb_to_hsv(
        mcolors.to_rgb(plt.rcParams['figure.facecolor']))[2]
    if background_color<0.5:
        title_color=[0.8,0.8,1]
    else:
        title_color=np.array([19,6,84])/256
    fig.suptitle(style_label,x=0.01,ha='left',color=title_color,
                 fontsize=14,fontfamily='DejaVu Sans',fontweight='normal')
    plot_scatter(axs[0],prng)
    plot_image_and_patch(axs[1],prng)
    plot_bar_graphs(axs[2],prng)
    plot_colored_lines(axs[3])
    plot_histograms(axs[4],prng)
    plot_colored_circles(axs[5],prng)
  	# 添加分隔线
    rec=Rectangle((1+0.025,-2),0.05,16,
                    clip_on=False,color='gray')
    axs[4].add_artist(rec)

# 保存图片
    plt.savefig(f'{style_label}.png', dpi=600)
    plt.close(fig)  # 关闭当前图形以避免内存占用过多

if __name__=="__main__":
  	# 获取所有可用的样式列表,按字母顺序排列
    style_list=['default','classic']+sorted(
        style for style in plt.style.available
        if style !='classic' and not style.startswith('_'))

    # 绘制每种样式的演示图
    for style_label in style_list:
        with plt.rc_context({"figure.max_open_warning":len(style_list)}):
            with plt.style.context(style_label):
                plot_figure(style_label=style_label)
    plt.show()
表格风格图_bmh
表格风格图_classic
表格风格图_dark_background
表格风格图_default
表格风格图_fast
表格风格图_fivethirtyeight
表格风格图_ggplot
表格风格图_grayscale
表格风格图_petroff10
表格风格图_seaborn-v0_8
表格风格图_seaborn-v0_8-bright
表格风格图_seaborn-v0_8-colorblind
表格风格图_seaborn-v0_8-dark
表格风格图_seaborn-v0_8-darkgrid
表格风格图_seaborn-v0_8-dark-palette
表格风格图_seaborn-v0_8-deep
表格风格图_seaborn-v0_8-muted
表格风格图_seaborn-v0_8-notebook
表格风格图_seaborn-v0_8-paper
表格风格图_seaborn-v0_8-pastel
表格风格图_seaborn-v0_8-poster
表格风格图_seaborn-v0_8-talk
表格风格图_seaborn-v0_8-ticks
表格风格图_seaborn-v0_8-white
表格风格图_seaborn-v0_8-whitegrid
表格风格图_Solarize_Light2
表格风格图_tableau-colorblind10

使用Seaborn函数绘图

import seaborn as sns
import matplotlib.pyplot as plt

# 加载数据集
iris=sns.load_dataset("iris",data_home='seaborn-data',cache=True)
tips=sns.load_dataset("tips",data_home='seaborn-data',cache=True)
car_crashes=sns.load_dataset("car_crashes",data_home='seaborn-data',cache=True)
penguins=sns.load_dataset("penguins",data_home='seaborn-data',cache=True)
diamonds=sns.load_dataset("diamonds",data_home='seaborn-data',cache=True)

plt.figure(figsize=(15,8))				# 设置画布
# 第1幅图:iris数据集的散点图
plt.subplot(2,3,1)
sns.scatterplot(x="sepal_length",y="sepal_width",hue="species",
                   data=iris)
plt.title("Iris scatterplot")

# 第2幅图:tips 数据集的箱线图
plt.subplot(2,3,2)
tips=sns.load_dataset("tips",data_home='seaborn-data',cache=True)
sns.boxplot(x="day",y="total_bill",hue="smoker",data=tips)
plt.title("Tips boxplot")

# 第3幅图:tips 数据集的小提琴图
plt.subplot(2,3,3)
sns.violinplot(x="day",y="total_bill",hue="smoker",data=tips)
plt.title("Tips violinplot")

# 第4幅图:car_crashes 数据集的直方图
plt.subplot(2,3,4)
sns.histplot(car_crashes['total'],bins=20)
plt.title("Car Crashes histplot")

# 第5幅图:penguins 数据集的点图
plt.subplot(2,3,5)
sns.pointplot(x="island",y="bill_length_mm",hue="species",data=penguins)
plt.title("Penguins pointplot")

# 第6幅图:diamonds 数据集的计数图
plt.subplot(2,3,6)
sns.countplot(x="cut",data=diamonds)
plt.title("Diamonds countplot")

plt.tight_layout()

# 保存图片
plt.savefig('P75使用Seaborn函数绘图.png', dpi=600, transparent=True)
plt.show()
使用Seaborn函数绘图

设置图表风格

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_style("darkgrid")			# 设置图表风格为 darkgrid
iris=sns.load_dataset("iris")		# 加载 iris 数据集

# 绘制花瓣长度与宽度的散点图
sns.scatterplot(x="petal_length",y="petal_width",
                   hue="species",data=iris)
plt.title("Scatter Plot of Petal Length vs Petal Width")

# 保存图片
plt.savefig('P77设置图表风格.png', dpi=600, transparent=True)
plt.show()
设置图表风格

设置颜色主题

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_palette("deep")				# 设置颜色主题为deep
tips=sns.load_dataset("tips")		# 加载 tips 数据集

# 绘制小费金额的小提琴图,按照就餐日期和吸烟者区分颜色
sns.violinplot(x="day",y="total_bill",hue="smoker",data=tips)
plt.title("Tips violinplot")		# 设置图表标题

# 保存图片
plt.savefig('P78设置颜色主题.png', dpi=600, transparent=True)
plt.show()
设置颜色主题

图表分面

import seaborn as sns
import matplotlib.pyplot as plt

iris=sns.load_dataset("iris")			# 加载iris数据集

# 创建 FacetGrid 对象,按照种类('species')进行分面
g=sns.FacetGrid(iris,col="species",margin_titles=True)
# 在每个子图中绘制花萼长度与花萼宽度的散点图
g.map(sns.scatterplot,"sepal_length","sepal_width")
g.set_axis_labels("Sepal Length","Sepal Width")		# 设置子图标题

# 保存图片
plt.savefig('P80图表分面.png', dpi=600, transparent=True)
plt.show()
图表分面

绘图过程

from plotnine import *
import seaborn as sns
import warnings

# 忽略 PlotnineWarning
warnings.filterwarnings("ignore", category=UserWarning, module="plotnine")

# 加载数据集
penguins = sns.load_dataset("penguins", data_home='seaborn-data', cache=True)

# 检查并处理缺失值
penguins = penguins.dropna()

# 创建画布和导入数据
p = ggplot(penguins, aes(x='bill_length_mm', y='bill_depth_mm', color='species'))

# 添加几何对象图层-散点图,并进行美化
p = p + geom_point(size=3, alpha=0.7)

# 设置标度
p = p + scale_x_continuous(name='Length (mm)')
p = p + scale_y_continuous(name='Depth (mm)')

# 设置主题和其他参数
p = p + theme(legend_position='top', figure_size=(6, 4))

# 保存绘图
ggsave(p, filename="P82绘图过程.png", width=6, height=4, dpi=600)
绘图过程

使用绘图函数绘图

import warnings
from plotnine import *
from plotnine.data import *

# 忽略 PlotnineWarning
warnings.filterwarnings("ignore", category=UserWarning, module="plotnine")

# 散点图-mpg 数据集
p1 = (ggplot(mpg) +
      aes(x='displ', y='hwy') +
      geom_point(color='blue') +
      labs(title='Displacement vs Highway MPG') +
      theme(plot_title=element_text(size=14, face='bold')))

# 箱线图-diamonds 数据集
p2 = (ggplot(diamonds.sample(1000)) +
      aes(x='cut', y='price', fill='cut') +
      geom_boxplot() +
      labs(title='Diamond Price by Cut') +
      scale_fill_brewer(type='qual', palette='Pastel1') +
      theme(plot_title=element_text(size=14, face='bold')))

# 直方图-msleep 数据集
p3 = (ggplot(msleep) +
      aes(x='sleep_total') +
      geom_histogram(bins=20, fill='green', color='black') +
      labs(title='Total Sleep in Mammals') +
      theme(plot_title=element_text(size=14, face='bold')))

# 线图-economics 数据集
p4 = (ggplot(economics) +
      aes(x='date', y='unemploy') +
      geom_line(color='red') +
      labs(title='Unemployment over Time') +
      theme(plot_title=element_text(size=14, face='bold')))

# 条形图-presidential 数据集
presidential['duration'] = (presidential['end'] - presidential['start']).dt.days
p5 = (ggplot(presidential) +
      aes(x='name', y='duration', fill='name') +
      geom_bar(stat='identity') +
      labs(title='Presidential Terms Duration') +
      scale_fill_hue(s=0.90, l=0.65) +
      theme(axis_text_x=element_text(rotation=90, hjust=1),
            plot_title=element_text(size=14, face='bold')))

# 折线图-midwest 数据集
p6 = (ggplot(midwest) +
      aes(x='area', y='popdensity') +
      geom_line(color='purple') +
      labs(title='Population Density vs Area') +
      theme(plot_title=element_text(size=14, face='bold')))

# 保存图片
plots = [p1, p2, p3, p4, p5, p6]
plot_names = ['scatter_plot', 'boxplot', 'histogram', 'line_plot', 'bar_plot', 'line_chart']

for plot, name in zip(plots, plot_names):
    plot.save(f'P85使用绘图函数绘图_{name}.png', width=8, height=6, dpi=600, transparent=True)
使用绘图函数绘图_bar_plot
使用绘图函数绘图_boxplot
使用绘图函数绘图_histogram
使用绘图函数绘图_line_chart
使用绘图函数绘图_line_plot
使用绘图函数绘图_scatter_plot

定义主题

from plotnine import *
from plotnine.data import mpg

# 创建散点图
p = (ggplot(mpg, aes(x='displ', y='hwy', color='displ')) +
     geom_point() +  # 添加点图层
     scale_color_gradient(low='blue', high='red') +  # 设置颜色渐变
     labs(title='Engine Displacement vs. Highway MPG',  # 设置图表标题
          x='Engine Displacement (L)',  # 设置x轴标题
          y='Miles per Gallon (Highway)') +  # 设置y轴标题
     theme_minimal() +  # 使用最小主题
     theme(axis_text_x=element_text(angle=45, hjust=1),  # 自定义x轴文字样式
           axis_text_y=element_text(color='darkgrey'),  # 自定义y轴文字样式
           plot_background=element_rect(fill='whitesmoke'),  # 自定义图表背景色
           panel_background=element_rect(fill='white', color='black', size=0.5),  # 自定义面板背景和边框
           panel_grid_major=element_line(color='lightgrey'),  # 自定义主要网格线颜色
           panel_grid_minor=element_line(color='lightgrey', linestyle='--'),  # 自定义次要网格线样式
           legend_position='right',  # 设置图例位置
           figure_size=(8, 6)))  # 设置图形大小

# 保存图片
p.save('P88定义主题.png', dpi=600, transparent=True)

# 显示图形
print(p)
定义主题

分面1

from plotnine import *
from plotnine.data import mpg

# 创建散点图并按照`class`变量进行分面,添加颜色渐变
p = (ggplot(mpg, aes(x='displ', y='hwy', color='displ')) +
     geom_point() +
     scale_color_gradient(low='blue', high='orange') +  # 添加颜色渐变
     facet_wrap('~class') +  # 按照汽车类型分面
     labs(title='Engine Displacement vs. Highway MPG by Vehicle Class',
          x='Engine Displacement (L)',
          y='Miles per Gallon (Highway)'))

# 保存图片
p.save('P89分面1.png', dpi=600, transparent=True)

# 显示图片
p.draw()
分面1

分面2

from plotnine import *
from plotnine.data import mpg

# 创建散点图并按照class变量进行分面,根据drv变量映射颜色
p=(ggplot(mpg,aes(x='displ',y='hwy',color='drv'))+
     geom_point()+						# 添加点图层
     scale_color_brewer(type='qual',palette='Set1')+	# 使用定性的颜色方案
     facet_grid('drv ~ class')+			# 行是驱动类型,列是汽车类型
     labs(title='Engine Displacement vs. Highway MPG by Vehicle Class',
          x='Engine Displacement (L)',
          y='Miles per Gallon (Highway)')+
     theme_light()+ 						# 使用亮色主题
     theme(figure_size=(10,6),			# 调整图形大小
           strip_text_x=element_text(size=10,color='black',angle=0),
						            			# 自定义分面标签的样式
           legend_title=element_text(color='blue',size=10),
						            			# 自定义图例标题的样式
           legend_text=element_text(size=8),		# 自定义图例文本的样式
           legend_position='right'))	# 调整图例位置

# 保存图片
p.save('P90分面2.png', dpi=600, transparent=True)

# 显示图片
p.draw()
分面2

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2405668.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

低空城市场景下的多无人机任务规划与动态协调!CoordField:无人机任务分配的智能协调场

作者&#xff1a;Tengchao Zhang 1 ^{1} 1 , Yonglin Tian 2 ^{2} 2 , Fei Lin 1 ^{1} 1, Jun Huang 1 ^{1} 1, Patrik P. Sli 3 ^{3} 3, Rui Qin 2 , 4 ^{2,4} 2,4, and Fei-Yue Wang 5 , 1 ^{5,1} 5,1单位&#xff1a; 1 ^{1} 1澳门科技大学创新工程学院工程科学系&#xff0…

算法-构造题

#include<iostream> #include<bits/stdc.h> using namespace std; typedef long long ll; const ll N 5e5 10; int main() {ll n, k;cin >> n >> k; ll a[N] {0}; // 初始化一个大小为N的数组a&#xff0c;用于存储排列// 构造满足条件的排列for (l…

【Linux】进程的基本概念

目录 概念描述进程-PCB如何查看进程通过系统目录进行查看通过ps指令进行查看 通过系统调用获取进程的PID和PPID(进程标⽰符)通过系统调用创建子进程通过一段代码来介绍fork为什么要有子进程&#xff1f;fork为什么给子进程返回0&#xff0c;给父进程返回子进程的PIDfork函数到底…

设备驱动与文件系统:05 文件使用磁盘的实现

从文件使用磁盘的实现逻辑分享 我们现在讲第30讲&#xff0c;内容是文件使用磁盘的具体实现&#xff0c;也就是相关代码是如何编写的。上一节我们探讨了如何从字符流位置算出盘块号&#xff0c;这是文件操作磁盘的核心。而这节课&#xff0c;我们将深入研究实现这一核心功能的…

AI数据分析在体育中的应用:技术与实践

在现代体育竞技领域&#xff0c;"数据驱动"已不再是一个遥远的概念。尤其随着人工智能&#xff08;AI&#xff09;和大数据分析的不断成熟&#xff0c;从职业俱乐部到赛事直播平台&#xff0c;从运动员训练到球迷观赛体验&#xff0c;AI正以前所未有的方式渗透并改变…

zabbix 6 监控 docker 容器

zabbix 6 监控 docker 容器 1.安装zabbix_agent2 curl -s http://10.26.211.56:8080/centos7-agent2-install.sh | bash2.在zabbix server 端测试 zabbix_get -s 10.26.219.180 -k docker.infoZBX_NOTSUPPORTED: Cannot fetch data: Get "http://1.28/info": dial…

正则持续学习呀

源匹配为 (.*): (.*)$ 替换匹配为 "$1": "$2", 可将headers改为字典 参考 【爬虫军火库】如何优雅地复制请求头 - 知乎

Go基本语法——go语言中的四种变量定义方法

前言 在go语言中&#xff0c;定义一个变量有四种方式&#xff0c;本文单从语法的层面来介绍这几种方式 单变量定义方法 1.var 变量名 类型&#xff0c;不进行初始化 例如&#xff0c;定义一个变量a后为其赋值&#xff0c;并且打印其值&#xff0c;运行结果如下 //1.不进行…

27.【新型数据架构】-数据共享架构

27.【新型数据架构】-数据共享架构:降低数据获取成本,实时数据访问,保持数据新鲜度,促进数据经济发展,打破数据孤岛,标准化数据交换,增强数据安全性,完整审计追踪,合规性保障 一、数据共享架构的本质:打破壁垒的“数字立交桥” 传统企业或组织间的数据往往呈现“烟囱…

virtualbox 如何虚拟机ip固定

1、在网络管理里新建 2、配置网络 3、 进入linux系统&#xff0c;查看 查看 网卡是enp0s8, ifconfig 4、进入网卡配置文件 cd /etc/sysconfig/network-scripts如果没有enp0s8 &#xff0c;则使用mv ifcfg-enp0s3 ifcfg-enp0s8命令 配置项如下 TYPEEthernet PROXY_METHODn…

RKNN3588上部署 RTDETRV2

RT-DETR V2 是由百度研究团队在 2024年 提出的&#xff0c;是其广受好评的实时目标检测模型 RT-DETR 的重大升级版本。它继承了第一代 RT-DETR 利用 Transformer 架构实现端到端目标检测 和 卓越实时性能 的核心优势&#xff0c;并针对模型精度、训练效率和部署灵活性进行了全方…

Python----循环神经网络(BiLSTM:双向长短时记忆网络)

一、LSTM 与 BiLSTM对比 1.1、LSTM LSTM&#xff08;长短期记忆网络&#xff09; 是一种改进的循环神经网络&#xff08;RNN&#xff09;&#xff0c;专门解决传统RNN难以学习长期依赖的问题。它通过遗忘门、输入门和输出门来控制信息的流动&#xff0c;保留重要信息并丢弃无关…

Linux系统编程-DAY10(TCP操作)

一、网络模型 1、服务器/客户端模型 &#xff08;1&#xff09;C/S&#xff1a;client server &#xff08;2&#xff09;B/S&#xff1a;browser server &#xff08;3&#xff09;P2P&#xff1a;peer to peer 2、C/S与B/S区别 &#xff08;1&#xff09;客户端不同&#…

基于eclipse进行Birt报表开发

Birt报表开发最终实现效果&#xff1a; 简洁版的Birt报表开发实现效果&#xff0c;仅供参考&#xff01; 可动态获取采购单ID&#xff0c;来打印出报表&#xff01; 下面开始Birt报表开发教程&#xff1a; 首先&#xff1a;汉化的eclipse及Birt值得拥有&#xff1a;至少感觉上…

GPU虚拟化

引言 现有如下环境&#xff08;注意相关配置&#xff1a;只有一个k8s节点&#xff0c;且该节点上只有一张GPU卡&#xff09;&#xff1a; // k8s版本 $ kubectl version Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.7&…

LabVIEW工业级多任务实时测控系统

采用LabVIEW构建了一套适用于工业自动化领域的多任务实时测控系统。系统采用分布式架构&#xff0c;集成高精度数据采集、实时控制、网络通信及远程监控等功能&#xff0c;通过硬件与软件的深度协同&#xff0c;实现对工业现场多类型信号的精准测控&#xff0c;展现 LabVIEW 在…

破解HTTP无状态:基于Java的Session与Cookie协同工作指南

HTTP协议自身是属于“无状态”协议 无状态是指&#xff1a;默认情况下&#xff0c;HTTP协议的客户端和服务器之间的这次通信&#xff0c;和下次通信之间没有直接的关系 但在实际开发中&#xff0c;我们很多时候是需要知道请求之间的关联关系的 上述图中的令牌&#xff0c;通常就…

JS 事件流机制详解:冒泡、捕获与完整事件流

JS 事件流机制详解&#xff1a;冒泡、捕获与完整事件流 文章目录 JS 事件流机制详解&#xff1a;冒泡、捕获与完整事件流一、DOM 事件流基本概念二、事件捕获 (Event Capturing)特点代码示例 三、事件冒泡 (Event Bubbling)特点代码示例 四、完整事件流示例HTML 结构JavaScript…

算法专题七:分治

快排 1.颜色分类 题目链接:75. 颜色分类 - 力扣(LeetCode) class Solution {public void swap(int[] nums, int i, int j){int t = nums[i];nums[i] = nums[j];nums[j] = t;}public void sortColors(int[] nums) {int left=-1 ,i=0 ,right=nums.length;while(i<right){i…

Vue中虚拟DOM的原理与作用

绪论 首先我们先了解&#xff0c;DOM&#xff08;Document Object Model&#xff0c;文档对象模型&#xff09; 是浏览器对 HTML/XML 文档的结构化表示&#xff0c;它将文档解析为一个由节点&#xff08;Node&#xff09;和对象组成的树形结构&#xff08;称为 DOM 树&#xf…