当前位置: 首页 > news >正文

比较(一)利用python绘制条形图

比较(一)利用python绘制条形图

条形图(Barplot)简介

1

条形图主要用来比较不同类别间的数据差异,一条轴表示类别,另一条则表示对应的数值度量。

快速绘制

  1. 基于seaborn

    import seaborn as sns
    import matplotlib.pyplot as plt# 导入数据
    tips = sns.load_dataset("tips")# 利用barplot函数快速绘制
    sns.barplot(x="total_bill", y="day", data=tips, estimator=sum, errorbar=None, color='#69b3a2')plt.show()
    

    2

  2. 基于matplotlib

    import matplotlib.pyplot as plt# 导入数据
    tips = sns.load_dataset("tips")
    grouped_tips = tips.groupby('day')['total_bill'].sum().reset_index()# 利用bar函数快速绘制
    plt.bar(grouped_tips.day, grouped_tips.total_bill)plt.show()
    

    3

  3. 基于pandas

    import matplotlib.pyplot as plt
    import pandas as pd# 导入数据
    tips = sns.load_dataset("tips")
    grouped_tips = tips.groupby('day')['total_bill'].sum().reset_index()# 利用plot.bar函数快速绘制
    grouped_tips.plot.bar(x='day', y='total_bill', rot=0)plt.show()
    

    4

定制多样化的条形图

自定义条形图一般是结合使用场景对相关参数进行修改,并辅以其他的绘图知识。参数信息可以通过官网进行查看,其他的绘图知识则更多来源于实战经验,大家不妨将接下来的绘图作为一种学习经验,以便于日后总结。

通过seaborn绘制多样化的条形图

seaborn主要利用barplot绘制条形图,可以通过seaborn.barplot了解更多用法

  1. 修改参数

    import seaborn as sns
    import matplotlib.pyplot as plt
    import numpy as npsns.set(font='SimHei', font_scale=0.8, style="darkgrid") # 解决Seaborn中文显示问题# 导入数据
    tips = sns.load_dataset("tips")# 构造子图
    fig, ax = plt.subplots(2,2,constrained_layout=True, figsize=(8, 8))# 修改方向-垂直
    ax_sub = sns.barplot(y="total_bill", x="day", data=tips, estimator=sum, errorbar=None, color='#69b3a2',ax=ax[0][0])
    ax_sub.set_title('垂直条形图')# 自定义排序
    ax_sub = sns.barplot(y="total_bill", x="day", data=tips, estimator=sum, errorbar=None, color='#69b3a2',order=["Fri","Thur","Sat","Sun"],ax=ax[0][1])
    ax_sub.set_title('自定义排序')# 数值排序
    df = tips.groupby('day')['total_bill'].sum().sort_values(ascending=False).reset_index()
    ax_sub = sns.barplot(y="day", x="total_bill", data=df, errorbar=None, color='#69b3a2',order=df['day'],ax=ax[1][0])
    ax_sub.set_title('数值排序')# 添加误差线
    ax_sub = sns.barplot(x="day", y="total_bill", data=tips, estimator=np.mean, errorbar=('ci', 85), capsize=.2, color='lightblue',ax=ax[1][1])
    ax_sub.set_title('添加误差线')plt.show()
    

    5

  2. 分组条形图

    import seaborn as sns
    import matplotlib.pyplot as plt
    import numpy as npsns.set(style="darkgrid")# 导入数据
    tips = sns.load_dataset("tips")fig, ax = plt.subplots(figsize=(4, 4))# 分组条形图
    colors = ["#69b3a2", "#4374B3"]
    sns.barplot(x="day", y="total_bill", hue="smoker", data=tips, errorbar=None, palette=colors)plt.show()# 分组/子分组条形图
    sns.catplot(x="sex", y="total_bill", hue="smoker", col="day", data=tips, kind="bar", height=4, aspect=.7)plt.show()
    

    6

  3. 引申-数量堆积条形图

    import seaborn as sns
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.patches as mpatchessns.set(style="darkgrid")# 导入数据
    tips = sns.load_dataset("tips")
    df = tips.groupby(['day', 'smoker'])['total_bill'].sum().reset_index()
    smoker_df = df[df['smoker']=='Yes']
    non_smoker_df = df[df['smoker']=='No']# 布局
    plt.figure(figsize=(6, 4))# 非吸烟者的条形图
    bar1 = sns.barplot(x='day', y='total_bill', data=non_smoker_df, color='lightblue')
    # 吸烟者的条形图,底部开始位置设置为非吸烟者的total_bill值(即吸烟者条形图在上面)
    bar2 = sns.barplot(x='day', y='total_bill', bottom=non_smoker_df['total_bill'], data=smoker_df, color='darkblue')# 图例
    top_bar = mpatches.Patch(color='darkblue', label='smoker = Yes')
    bottom_bar = mpatches.Patch(color='lightblue', label='smoker = No')
    plt.legend(handles=[top_bar, bottom_bar])plt.show()
    

    7

  4. 引申-百分比堆积条形图

    import seaborn as sns
    import matplotlib.pyplot as plt
    import pandas as pd# 导入数据
    tips = sns.load_dataset("tips")# 计算百分比
    day_total_bill = tips.groupby('day')['total_bill'].sum() # 每日数据
    group_total_bill = tips.groupby(['day', 'smoker'])['total_bill'].sum().reset_index() # 每日每组数据
    group_total_bill['percent'] = group_total_bill.apply(lambda row: row['total_bill'] / day_total_bill[row['day']] * 100, axis=1)# 将数据分成smoker和non-smoker两份,方便我们绘制两个条形图
    smoker_df = group_total_bill[group_total_bill['smoker'] == 'Yes']
    non_smoker_df = group_total_bill[group_total_bill['smoker'] == 'No']# 布局
    plt.figure(figsize=(6, 4))# 非吸烟者的条形图
    bar1 = sns.barplot(x='day', y='percent', data=non_smoker_df, color='lightblue')
    # 吸烟者的条形图,底部开始位置设置为非吸烟者的total_bill值(即吸烟者条形图在上面)
    bar2 = sns.barplot(x='day', y='percent', bottom=non_smoker_df['percent'], data=smoker_df, color='darkblue')# 图例
    top_bar = mpatches.Patch(color='darkblue', label='smoker = Yes')
    bottom_bar = mpatches.Patch(color='lightblue', label='smoker = No')
    plt.legend(handles=[top_bar, bottom_bar])plt.show()
    

    8

通过seaborn绘制多样化的条形图

seaborn主要利用barh绘制条形图,可以通过matplotlib.pyplot.barh了解更多用法

  1. 修改参数

    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import numpy as np 
    import pandas as pdmpl.rcParams.update(mpl.rcParamsDefault) # 恢复默认的matplotlib样式
    plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签# 自定义数据
    height = [3, 12, 5, 18, 45]
    bars = ('A', 'B', 'C', 'D', 'E')
    y_pos = np.arange(len(bars))
    x_pos = np.arange(len(bars))# 初始化布局
    fig = plt.figure(figsize=(8,8))# 水平方向-水平条形图
    plt.subplot(3, 3, 1) 
    plt.barh(y_pos, height)
    plt.yticks(y_pos, bars)
    plt.title('水平条形图')# 指定顺序
    height_order, bars_order = zip(*sorted(zip(height, bars), reverse=False)) # 自定义顺序plt.subplot(3, 3, 2) 
    plt.barh(y_pos, height_order)
    plt.yticks(y_pos, bars_order)
    plt.title('指定顺序')# 自定义颜色
    plt.subplot(3, 3, 3) 
    plt.bar(x_pos, height, color=['black', 'red', 'green', 'blue', 'cyan'])
    plt.xticks(x_pos, bars)
    plt.title('自定义颜色')# 自定义颜色-边框颜色
    plt.subplot(3, 3, 4) 
    plt.bar(x_pos, height, color=(0.1, 0.1, 0.1, 0.1),  edgecolor='blue')
    plt.xticks(x_pos, bars)
    plt.title('自定义边框颜色')# 控制距离
    width = [0.1,0.2,3,1.5,0.3]
    x_pos_width = [0,0.3,2,4.5,5.5]plt.subplot(3, 3, 5) 
    plt.bar(x_pos_width, height, width=width)
    plt.xticks(x_pos_width, bars)
    plt.title('控制距离')# 控制宽度
    x_pos_space = [0,1,5,8,9]plt.subplot(3, 3, 6) 
    plt.bar(x_pos_space, height)
    plt.xticks(x_pos_space, bars)
    plt.title('控制宽度')# 自定义布局
    plt.subplot(3, 3, 7) 
    plt.bar(x_pos, height)
    plt.xticks(x_pos, bars, color='orange', rotation=90) # 自定义x刻度名称颜色,自定义旋转
    plt.xlabel('category', fontweight='bold', color = 'orange', fontsize='18') # 自定义x标签
    plt.yticks(color='orange') # 自定义y刻度名称颜色plt.title('自定义布局')# 添加误差线
    err = [val * 0.1 for val in height] # 计算误差(这里假设误差为height的10%)plt.subplot(3, 3, 8) 
    plt.bar(x_pos, height, yerr=err, alpha=0.5, ecolor='black', capsize=10)
    plt.xticks(x_pos, bars)
    plt.title('添加误差线')# 增加数值文本信息
    plt.subplot(3, 3, 9) 
    ax = plt.bar(x_pos, height)
    for bar in ax:yval = bar.get_height()plt.text(bar.get_x() + bar.get_width()/2.0, yval, int(yval), va='bottom') # va参数代表垂直对齐方式
    plt.xticks(x_pos, bars)
    plt.title('增加数值文本信息')fig.tight_layout() # 自动调整间距
    plt.show()
    

    9

  2. 分组条形图

    import numpy as np
    import matplotlib.pyplot as plt# 宽度设置
    barWidth = 0.25# 自定义数据
    bars1 = [12, 30, 1, 8, 22]
    bars2 = [28, 6, 16, 5, 10]
    bars3 = [29, 3, 24, 25, 17]# x位置
    r1 = np.arange(len(bars1))
    r2 = [x + barWidth for x in r1]
    r3 = [x + barWidth for x in r2]# 绘制分组条形图
    plt.bar(r1, bars1, color='#7f6d5f', width=barWidth, edgecolor='white', label='g1')
    plt.bar(r2, bars2, color='#557f2d', width=barWidth, edgecolor='white', label='g2')
    plt.bar(r3, bars3, color='#2d7f5e', width=barWidth, edgecolor='white', label='g3')# 轴标签、图例
    plt.xlabel('group', fontweight='bold')
    plt.xticks([r + barWidth for r in range(len(bars1))], ['A', 'B', 'C', 'D', 'E'])
    plt.legend()plt.show()
    

    10

  3. 数量堆积条形图

    import numpy as np
    import matplotlib.pyplot as plt
    import pandas as pd# 自定义数据
    bars1 = [12, 28, 1, 8, 22]
    bars2 = [28, 7, 16, 4, 10]
    bars3 = [25, 3, 23, 25, 17]# bars1 + bars2的高度
    bars = np.add(bars1, bars2).tolist()# x位置
    r = [0,1,2,3,4]# bar名称、宽度
    names = ['A','B','C','D','E']
    barWidth = 1# 底部bar
    plt.bar(r, bars1, color='#7f6d5f', edgecolor='white', width=barWidth, label="g1")
    # 中间bar
    plt.bar(r, bars2, bottom=bars1, color='#557f2d', edgecolor='white', width=barWidth, label="g2")
    # 顶部bar
    plt.bar(r, bars3, bottom=bars, color='#2d7f5e', edgecolor='white', width=barWidth, label="g3")# x轴设置、图例
    plt.xticks(r, names, fontweight='bold')
    plt.xlabel("group")
    plt.legend()plt.show()
    

    11

  4. 百分比堆积条形图

    import numpy as np
    import matplotlib.pyplot as plt
    import pandas as pd# 自定义数据
    r = [0,1,2,3,4] # x位置
    raw_data = {'greenBars': [20, 1.5, 7, 10, 5], 'orangeBars': [5, 15, 5, 10, 15],'blueBars': [2, 15, 18, 5, 10]}
    df = pd.DataFrame(raw_data)# 转为百分比
    totals = [i+j+k for i,j,k in zip(df['greenBars'], df['orangeBars'], df['blueBars'])]
    greenBars = [i / j * 100 for i,j in zip(df['greenBars'], totals)]
    orangeBars = [i / j * 100 for i,j in zip(df['orangeBars'], totals)]
    blueBars = [i / j * 100 for i,j in zip(df['blueBars'], totals)]# bar名称、宽度
    barWidth = 0.85
    names = ('A','B','C','D','E')# 底部bar
    plt.bar(r, greenBars, color='#b5ffb9', edgecolor='white', width=barWidth, label="g1")
    # 中间bar
    plt.bar(r, orangeBars, bottom=greenBars, color='#f9bc86', edgecolor='white', width=barWidth, label="g2")
    # 顶部bar
    plt.bar(r, blueBars, bottom=[i+j for i,j in zip(greenBars, orangeBars)], color='#a3acff', edgecolor='white', width=barWidth, label="g3")# x轴、图例
    plt.xticks(r, names)
    plt.xlabel("group")
    plt.legend()plt.show()
    

    12

通过pandas绘制多样化的条形图

pandas主要利用barh绘制条形图,可以通过pandas.DataFrame.plot.barh了解更多用法

  1. 修改参数

    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import numpy as np 
    import pandas as pdplt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签# 自定义数据
    category = ['Group1']*30 + ['Group2']*50 + ['Group3']*20
    df = pd.DataFrame({'category': category})
    values = df['category'].value_counts()# 初始化布局
    fig = plt.figure(figsize=(8,4))# 水平方向-水平条形图
    plt.subplot(1, 2, 1) 
    values.plot.barh(grid=True)
    plt.title('水平条形图')# 自定义顺序、颜色
    # 指定顺序
    desired_order = ['Group1', 'Group2', 'Group3']
    values_order = values.reindex(desired_order)
    # 指定颜色
    colors = ['#69b3a2', '#cb1dd1', 'palegreen']plt.subplot(1, 2, 2) 
    values.plot.bar(color=colors,grid=True, )  
    plt.title('自定义顺序、颜色')fig.tight_layout() # 自动调整间距
    plt.show()
    

    13

  2. 分组条形图

    import pandas as pd
    import matplotlib.pyplot as plt# 自定义数据
    data = {"Product": ["Product A", "Product A", "Product A", "Product B", "Product B", "Product B"],"Segment": ["Segment 1", "Segment 2", "Segment 3", "Segment 1", "Segment 2", "Segment 3"],"Amount_sold": [100, 120, 120, 80, 160, 150]
    }df = pd.DataFrame(data)
    pivot_df = df.pivot(index='Segment',columns='Product',values='Amount_sold')# 分组条形图
    pivot_df.plot.bar(grid=True)plt.show()
    

    14

  3. 数量堆积条形图

    import pandas as pd
    import matplotlib.pyplot as plt# 自定义数据
    data = {"Product": ["Product A", "Product A", "Product A", "Product B", "Product B", "Product B"],"Segment": ["Segment 1", "Segment 2", "Segment 3", "Segment 1", "Segment 2", "Segment 3"],"Amount_sold": [100, 120, 120, 80, 160, 150]
    }df = pd.DataFrame(data)
    pivot_df = df.pivot(index='Segment',columns='Product',values='Amount_sold')# 堆积条形图
    pivot_df.plot.bar(stacked=True,grid=True)plt.show()
    

    15

  4. 百分比堆积条形图

    import pandas as pd
    import matplotlib.pyplot as plt# 自定义数据
    data = {"Product": ["Product A", "Product A", "Product A", "Product B", "Product B", "Product B"],"Segment": ["Segment 1", "Segment 2", "Segment 3", "Segment 1", "Segment 2", "Segment 3"],"Amount_sold": [100, 120, 120, 80, 160, 150]
    }df = pd.DataFrame(data)
    pivot_df = df.pivot(index='Segment',columns='Product',values='Amount_sold')
    pivot_df_percentage = pivot_df.div(pivot_df.sum(axis=1), axis=0) * 100# 百分比堆积条形图
    pivot_df_percentage.plot.bar(stacked=True,grid=True)# 图例
    plt.legend(bbox_to_anchor=(1.04, 1),loc='upper left')
    plt.show()
    

    16

总结

以上通过seaborn的barplot、matplotlib的bar和pandas的bar快速绘制条形图,并通过修改参数或者辅以其他绘图知识自定义各种各样的条形图来适应相关使用场景。

共勉~

相关文章:

比较(一)利用python绘制条形图

比较(一)利用python绘制条形图 条形图(Barplot)简介 条形图主要用来比较不同类别间的数据差异,一条轴表示类别,另一条则表示对应的数值度量。 快速绘制 基于seaborn import seaborn as sns import matplo…...

【面试】Oracle JDK和Open JDK什么关系?

目录 1. 起源与发展2. 代码与许可3. 功能与组件4. 使用场景5. 版本更新与支持 1. 起源与发展 1.Oracle JDK是由Oracle公司基于Open JDK源代码开发的商业版本。2.Open JDK是java语言的一个开源实现。 2. 代码与许可 1.Oracle JDK包含了闭源组件,并根据二进制代码许…...

科学技术创新杂志科学技术创新杂志社科学技术创新编辑部2024年第10期目录

科技创新 单桩穿越岩溶发育地层力学特征与溶洞处置措施研究 刘飞; 1-7《科学技术创新》投稿:cnqikantg126.com 基于多目标优化的中低压配电网电力规划研究 向星山;杨承俊;张寒月; 8-11 激光雷达测绘技术在工程测绘中的应用研究 张军伟;闫宏昌; 12-15 …...

ES数据导出成csv文件

推荐使用es2csv 工具。 命令行实用程序,用Python编写,用于用Lucene查询语法或查询DSL语法查询Elasticsearch,并将结果作为文档导出到CSV文件中。该工具可以在多个索引中查询批量文档,并且只获取选定的字段,这减少了查…...

结构型设计模式之装饰模式

文章目录 概述装饰模式原理代码案例小结 概述 装饰模式(decorator pattern) 的原始定义是:动态的给一个对象添加一些额外的职责. 就扩展功能而言,装饰器模式提供了一种比使用子类更加灵活的替代方案。 装饰模式原理 装饰模式中的角色: 抽象构件角色 …...

Java - 当年很流行,现在已经淘汰的 Java 技术,请不要在继续学了!!!

最近这段时间收到了一些读者的私信,问我某个技术要不要学,还有一些在国外的同学竟然对 Java 图形化很感兴趣,还想找这方面的工作。 比较忙,一直没抽出时间去回答这类问题,刚好看到我关注的一位大佬回答过,这…...

驻波比VSWR

最近看大家写的VSWR文章,发现有很多误解, 1)错误解释是入射波和反射波叠加的驻波的波峰/波谷。大家可以向下驻波也是正弦波,波峰和波谷的值不都是振幅吗?因此相当于VSWR恒等于1了。 2)VSWR越小越好; 正确…...

多线程-线程池

为什么要使用线程池 在Java中使用线程池的主要原因有以下几点: 提高性能:使用线程池可以减少线程的创建和销毁过程的开销。线程的创建和销毁是比较昂贵的操作,如果每次需要执行任务时都创建一个新线程,会造成系统资源的浪费。而线…...

护网期间遇到的几个上传bypass waf、edr

1. weblogic部署war的时候 http/1.1 改成http/2绕过waf 其实jar和ear部署应该也可以,但是我没成功。 weblogoic 部署war死活出错,用linux下的浏览器 linux下打包war马 zip -r zipjob4.zip job/ mv zipjob3.zip zipjob3.war 然后部署成功之后&am…...

简述MVC模式

这里为什么讲MVC模式,是因为在学习的过程中,很多人不知怎的,将观察者模式和MVC混为一谈。MVC模式最开始出现在WEB开发中,该模式能够很好的做到软件模块的高内聚,低耦合,所以其思想逐渐在各个软件开发领域都…...

C#--Mapster(高性能映射)用法

1.Nuget安装Mapster包引用 2.界面XAML部分 <Window x:Class"WpfApp35.MainWindow"xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x"http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d"http://schemas.m…...

mysql实战——Mysql8.0高可用之双主+keepalived

一、介绍 利用keepalived实现Mysql数据库的高可用&#xff0c;KeepalivedMysql双主来实现MYSQL-HA&#xff0c;两台Mysql数据库的数据保持完全一致&#xff0c;实现方法是两台Mysql互为主从关系&#xff0c;通过keepalived配置VIP&#xff0c;实现当其中的一台Mysql数据库宕机…...

关于同一个地址用作两个不同页面时,列表操作栏按钮混淆状态

同一个地址用作两个不同页面时&#xff0c;列表页的操作栏中有好多个按钮&#xff0c;如果用了v-if&#xff0c;可能会导致按钮混淆状态如disabled等属性混乱 解决方法1&#xff1a; 将v-if换成v-show&#xff0c;用了v-show之后意味着所有按钮都在只是在页面上隐藏了 解决方…...

Oracle段延迟分配(Deferred Segment Creation)解析

目录 一、基本概念二、工作原理三、优势四、潜在风险与注意事项五、配置与管理 Oracle段延迟分配&#xff08;Deferred Segment Creation&#xff09;是Oracle 11g引入的一项重要特性&#xff0c;旨在优化资源使用和提高数据库管理效率。 一、基本概念 段延迟分配意味着当创建…...

Linux:IPC - System V

Linux&#xff1a;IPC - System V 共享内存 shm创建共享内存shmgetshmctlftok 挂接共享内存shmatshmdt shm特性 消息队列 msgmsggetmsgctlmsgsndmsgrcv 信号量 semSystem V 管理机制 System V IPC 是Linux系统中一种重要的进程间通信机制&#xff0c;它主要包括共享内存 shm&am…...

Laravel 图片添加水印

和这个配合使用 Laravel ThinkPhP 海报生成_laravel 制作海报-CSDN博客 代码 //水印 $x_length $imageInfo[0]; $y_length $imageInfo[1];$color imagecolorallocatealpha($posterImage, 255, 255, 255, 70); // 增加透明度参数alpha$font_size 40; //字体大小 $angle …...

嵌入式进阶——矩阵键盘

&#x1f3ac; 秋野酱&#xff1a;《个人主页》 &#x1f525; 个人专栏:《Java专栏》《Python专栏》 ⛺️心若有所向往,何惧道阻且长 文章目录 矩阵按键原理图按键状态检测单行按键状态检测多行按键状态检测 状态记录状态优化循环优化 矩阵按键 矩阵键盘是一种常见的数字输入…...

请说出vue.cli项目中src目录每个文件夹和文件的用法

在Vue CLI项目中&#xff0c;src目录是存放项目源码及需要引用的资源文件的主要位置。以下是src目录下常见文件夹和文件的用法&#xff1a; components 用途&#xff1a;存放可重用的Vue组件。这些组件通常用于在多个页面或布局中共享UI和功能。特点&#xff1a;组件应该是模块…...

【MySQL精通之路】InnoDB磁盘I/O和文件空间管理(11)

主博客&#xff1a; 【MySQL精通之路】InnoDB存储引擎-CSDN博客 目录 1.InnoDB磁盘I/O 1.1 预读 1.2 双写缓冲区 2.文件空间管理 2.1 Pages, Extents, Segments, and Tablespaces&#xff08;很重要&#xff09; 2.2 配置保留文件段页面的百分比 2.3 页与表行的关系 …...

基于springboot+html的二手交易平台(附源码)

基于springboothtml的二手交易平台 介绍部分界面截图如下联系我 介绍 本系统是基于springboothtml的二手交易平台&#xff0c;数据库为mysql&#xff0c;可用于毕设或学习&#xff0c;附数据库 部分界面截图如下 联系我 VX&#xff1a;Zzllh_...

正点原子[第二期]Linux之ARM(MX6U)裸机篇学习笔记-24.3,4 SPI驱动实验-I.MX6U SPI 寄存器

前言&#xff1a; 本文是根据哔哩哔哩网站上“正点原子[第二期]Linux之ARM&#xff08;MX6U&#xff09;裸机篇”视频的学习笔记&#xff0c;在这里会记录下正点原子 I.MX6ULL 开发板的配套视频教程所作的实验和学习笔记内容。本文大量引用了正点原子教学视频和链接中的内容。…...

【Pandas】数据处理方法

1.数据拆分 pandas.Series.str.extract() Series.str.extract(pat, flags0, expandTrue)[source]extract(提取) 参数 pat: 带分组的正则表达式。 flag: re模块中的标志&#xff0c;例如re.IGNORECASE&#xff0c;修改正则表达式匹配的大小写、空格等 expand: 默认为True&…...

【ArcGIS For JS】前端geojson渲染行政区划图层并加标签

原理 通过DataV工具 生成行政区的geojson&#xff08;得到各区的面元素数据&#xff09;, 随后使用手动绘制featureLayer与Label&#xff0c;并加载到地图。 //vue3加载geojson数据public/geojson/pt.json,在MapView渲染上加载geojson数据 type是"MultiPolygon"fetc…...

Spring AOP原理详解:动态代理与实际应用

1. Spring AOP概述 1.1 什么是AOP AOP&#xff08;Aspect-Oriented Programming&#xff0c;面向切面编程&#xff09;是一种编程范式&#xff0c;旨在将横切关注点&#xff08;Cross-Cutting Concerns&#xff09;从业务逻辑中分离出来。横切关注点是指那些分散在应用程序多…...

死锁的四个必要条件

死锁的四个必要条件如下&#xff1a; 互斥条件&#xff08;Mutual Exclusion&#xff09;&#xff1a;资源是独占的&#xff0c;即在同一时间内一个资源只能被一个进程或线程所使用&#xff0c;其他进程或线程无法访问该资源。 请求与保持条件&#xff08;Hold and Wait&#…...

源网络地址转换SNAT

左上角的是访问互联网发送的数据包&#xff0c;第一个是访问&#xff0c;第二个是网页传回来的 3、4项是源端口号和目的端口号&#xff08;3是随机的&#xff08;1024-65535&#xff09;&#xff0c;那个是http的网页服务端口就是80&#xff09; 那么往回传数据的时候源和目的…...

【算法】平衡二叉搜索树的左旋和右旋

树旋转是一种维护平衡树结构的重要操作&#xff0c;主要用于平衡二叉搜索树&#xff08;如AVL树和红黑树&#xff09;。树旋转分为左旋和右旋。 1. 树旋转的定义 左旋 (Left Rotation) 左旋操作将节点及其右子树进行调整&#xff0c;使其右子树的左子节点成为根节点&#xf…...

介绍Django Ninja框架

文章目录 安装快速开始特性详解自动文档生成定义请求和响应模型异步支持中间件支持测试客户端 结论 Django Ninja是一个基于Python的快速API开发框架&#xff0c;它结合了Django和FastAPI的优点&#xff0c;提供了简单易用的方式来构建高性能的Web API。 安装 使用以下命令安…...

使用uniapp内置组件checkbox-group所遇到的问题

checkbox-group属性说明 属性名类型默认值说明changeEventHandle <checkbox-group> 中选项发生改变触发change事件 detail { value&#xff1a;[选中的checkbox的value的数组] } 问题代码 <checkbox-group change"handleEVent()"><view style&qu…...

嵌入式学习记录5.23(超时检测、抓包分析)

目录 一.自带超时参数的函数 1.1 select函数 1.2 poll函数的自带超时检测参数 二、不带超时检测参数的函数 三、通过信号完成时间的设置 四、更新下载源 五、wireshark使用 5.1. 安装 5.2. wireshark 抓包 5.2.1 wireshark与对应的OSI七层模型 ​编辑5.2.2 包头分析 …...