当前位置:网站首页>matplotlib plt. Specific usage of text() - labeling points in a drawing
matplotlib plt. Specific usage of text() - labeling points in a drawing
2022-06-10 17:32:00 【Guoqingru】
matplotlib plt.text() Specific usage of —— When drawing a picture, label the points in the picture

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

import pandas as pd # Import data analysis module
import matplotlib.pyplot as plt # Import drawing module class
plt.rcParams['font.sans-serif']=['SimHei'] # The Chinese font in the figure is set to bold
plt.rcParams['axes.unicode_minus']=False # Negative value display
data=pd.read_excel(r"D:\ City rental map \ People flow and epidemic development \ Baidu migration .xlsx") # Reading data
city_name=data['city'] # The city name
people_flow=data['out_people']*100 # Outflow population , The unit has 100 people
confirm=data['confirm(2.10)'] # Number of confirmed cases
fig=plt.figure(figsize=(8,6)) # New canvas
ax=plt.subplot(1,1,1) # Subgraph initialization
ax.scatter(people_flow,confirm) # Draw a scatter plot
ax.set_title(" Population inflow - Number of confirmed cases ")
ax.set_xlabel(" Population inflow ( Hundred people )")
ax.set_ylabel(" Number of confirmed cases ")
plt.show()

ax.text(430, 337, " Beijing ", 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) # Label the scatter

# -*- coding: utf-8 -*-
"""
Created on Sat Feb 15 10:29:38 2020
project name:add_annotation
@author: Handsome de Three uncles
"""
import pandas as pd # Import data analysis module
import matplotlib.pyplot as plt # Import drawing module class
plt.rcParams['font.sans-serif']=['SimHei'] # The Chinese font in the figure is set to bold
plt.rcParams['axes.unicode_minus']=False # Negative value display
data=pd.read_excel(r"D:\ City rental map \ People flow and epidemic development \ Baidu migration .xlsx") # Reading data
city_name=data['city'] # The city name
people_flow=data['out_people']*100 # Outflow population , The unit has 100 people
confirm=data['confirm(2.10)'] # Number of confirmed cases
fig=plt.figure(figsize=(8,6)) # New canvas
ax=plt.subplot(1,1,1) # Subgraph initialization
ax.scatter(people_flow,confirm) # Draw a scatter plot
ax.set_title(" Population inflow - Number of confirmed cases ")
ax.set_xlabel(" Population inflow ( Hundred people )")
ax.set_ylabel(" Number of confirmed cases ")
#ax.text(430, 337, " Beijing ", 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) # Label the scatter
plt.show()
边栏推荐
- Attributes of script tag
- Web3最全搞钱秘籍,看这一篇就够了
- com.netflix.client.ClientException: Load balancer does not have available server for client: userser
- Fabric.js 精简输出的JSON
- Nacos注册中心
- Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
- 创建 Visual Studio 离线安装包并安装
- 嘿!ONES 新星请看过来|师兄师姐说
- Internet enterprises and chips
- [BSP video tutorial] BSP video tutorial issue 17: single chip microcomputer bootloader topic, startup, jump configuration and various usage of debugging and downloading (2022-06-10)
猜你喜欢

线上交流丨技能网络:解决多任务多模态问题的稀疏模型(青源Talk第19期 唐都钰)

Detailed steps for installing redis image in docker (easy to understand, suitable for novices to get started quickly)

几个对程序员的误解,害人不浅!

Station B doesn't want to be a "conscience aiyouteng"

Brands are difficult to establish, IPO is difficult, and Chinese tea enterprises are trapped in "tradition"?

“挽弓当挽强,用箭当用长”,曼孚科技为数据服务行业开启新赛道

亟需丰富智能家居产品线,扫地机器人赛道上挤得下萤石吗?

Photoshop如何打开、编辑和导出Webp格式图片的方法

品牌难立,IPO难行,中国茶企困于“传统”?

自定义视图:图形与图像的处理(一):使用简单图片
随机推荐
Eliminate if Five ways of else
Redis通用指令
Xinsi technology performed well in the Gartner application security test key capability report 2022 and won the highest score among the five common use cases
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
几个对程序员的误解,害人不浅!
What is the highest compound interest insurance product? How much does it cost a year?
Fabric.js 居中元素 ️
When V-IF and V-for need to be used at the same time
Graduation season: to you
华为matepad能成为你的笔记本电脑副屏?
vscode常用插件与配置
[play with Huawei cloud] Kunpeng devkit migration practice
线上交流丨技能网络:解决多任务多模态问题的稀疏模型(青源Talk第19期 唐都钰)
【玩转华为云】手把手带你使用鲲鹏代码迁移工具实现源码迁移
Overseas data centers need to be prepared for unpredictable disasters
For more than 20 years, there are only Durex, Okamoto and jasbon in the condom market
为 Chocolatey 设置代理
ahk常用函数
2022年G2电站锅炉司炉考试模拟100题及模拟考试
Fabric. JS centered element