当前位置:网站首页>matplotlib plt.text()的具体用法——画图时给图中的点加标签
matplotlib plt.text()的具体用法——画图时给图中的点加标签
2022-06-10 16:37:00 【郭庆汝】
matplotlib plt.text()的具体用法——画图时给图中的点加标签

plt.text(x, y, s, fontsize, verticalalignment,horizontalalignment,rotation , **kwargs)

import pandas as pd #导入数据分析模块
import matplotlib.pyplot as plt #导入绘图模块类
plt.rcParams['font.sans-serif']=['SimHei'] #图中文字体设置为黑体
plt.rcParams['axes.unicode_minus']=False #负值显示
data=pd.read_excel(r"D:\城市租赁地图\人流流动与疫情发展\百度迁徙.xlsx") #读取数据
city_name=data['city'] #城市名称
people_flow=data['out_people']*100 #流出人口,单位百人
confirm=data['confirm(2.10)'] #确诊人数
fig=plt.figure(figsize=(8,6)) #新建画布
ax=plt.subplot(1,1,1) #子图初始化
ax.scatter(people_flow,confirm) #绘制散点图
ax.set_title("人口流入-确诊人数")
ax.set_xlabel("人口流入数(百人)")
ax.set_ylabel("确诊人数")
plt.show()

ax.text(430, 337, "北京", fontsize=12, color = "r", style = "italic", weight = "light", verticalalignment='center', horizontalalignment='right', rotation=90)

for i in range(len(confirm)):
ax.text(people_flow[i]*1.01, confirm[i]*1.01, city_name[i], fontsize=10, color = "r", style = "italic", weight = "light", verticalalignment='center', horizontalalignment='right',rotation=0) #给散点加标签

# -*- coding: utf-8 -*-
"""
Created on Sat Feb 15 10:29:38 2020
project name:add_annotation
@author: 帅帅de三叔
"""
import pandas as pd #导入数据分析模块
import matplotlib.pyplot as plt #导入绘图模块类
plt.rcParams['font.sans-serif']=['SimHei'] #图中文字体设置为黑体
plt.rcParams['axes.unicode_minus']=False #负值显示
data=pd.read_excel(r"D:\城市租赁地图\人流流动与疫情发展\百度迁徙.xlsx") #读取数据
city_name=data['city'] #城市名称
people_flow=data['out_people']*100 #流出人口,单位百人
confirm=data['confirm(2.10)'] #确诊人数
fig=plt.figure(figsize=(8,6)) #新建画布
ax=plt.subplot(1,1,1) #子图初始化
ax.scatter(people_flow,confirm) #绘制散点图
ax.set_title("人口流入-确诊人数")
ax.set_xlabel("人口流入数(百人)")
ax.set_ylabel("确诊人数")
#ax.text(430, 337, "北京", fontsize=12, color = "r", style = "italic", weight = "light", verticalalignment='center', horizontalalignment='right',rotation=90)
for i in range(len(confirm)):
ax.text(people_flow[i]*1.01, confirm[i]*1.01, city_name[i],
fontsize=10, color = "r", style = "italic", weight = "light",
verticalalignment='center', horizontalalignment='right',rotation=0) #给散点加标签
plt.show()
边栏推荐
- 期货账户资金安全吗?
- SOA architecture / test phase interface description language transformation scheme
- 开源项目 PM 浅谈如何设计官网
- 提升园区服务水平,优化营商环境该从哪些方面入手
- C# 根据EXCEL自动生成oracle建表语句
- Swift 3pThread tool Promise Pipeline Master/Slave Serial Thread confinement Serial queue
- Set up proxy for chocolate
- Mysql database implementation setting field length
- Graduation season: to you
- MFC basic knowledge and course design ideas
猜你喜欢

丢失的遗传力--Missing heritability

Internet enterprises and chips

ADB is not an internal or external command, nor is it a runnable program or batch file

华为matepad能成为你的笔记本电脑副屏?

Redis general instruction

Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data

大山深处的孩子,正在看见更远的星空

Make good use of the industrial chain to attract investment, create industrial cluster effect and realize the coordinated development of industries

Docker安装Redis镜像详细步骤(简单易懂,适合新手快速上手)

Photoshop如何打开、编辑和导出Webp格式图片的方法
随机推荐
fail-fast和fail-safe
AIChE | ab initio drug design framework integrating mathematical programming method and deep learning model
Example code of PHP for uploading multiple pictures
运筹说 第64期丨动态规划奠基人——理查德·贝尔曼
Hidden Markov model and its training (1)
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
ADB is not an internal or external command, nor is it a runnable program or batch file
Do you know the five GoLand shortcuts to improve efficiency?
Detailed derivation of perspective projection transformation and related applications
5年后,你将如何融入20万亿美元的「项目经济」
Take you to a preliminary understanding of the basic mechanism of classes and objects
script 标签自带的属性
隐形马尔可夫模型及其训练(一)
域名备案和icp备案有哪些区别?
自定义视图:图形与图像的处理(一):使用简单图片
Fabric. JS lock the background image, not affected by zooming and dragging
Intelligent scenic spot video monitoring 5g intelligent light pole gateway networking integrated pole
AHK common functions
【报表工具的第二次革命】基于SPL语言优化报表结构、提升报表运算性能
Richard Behrman, the founder of dynamic planning