当前位置:网站首页>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()
边栏推荐
- Fabric.js 精简输出的JSON
- Docker安装Redis镜像详细步骤(简单易懂,适合新手快速上手)
- Under the "plastic ban order", does the Hong Kong stock exchange pay for the deep excavation of degradable plastics by Zhongbao new materials?
- How to make a simple Snake game with pyGame
- IDEA的Swing可视化插件JFormDesigner
- Redis operation set, Zset, hash data types and use of visualization tools
- Brands are difficult to establish, IPO is difficult, and Chinese tea enterprises are trapped in "tradition"?
- Nat. Rev. Drug Discov. | AI在小分子药物发现中的应用:一个即将到来的浪潮?
- 2022年茶艺师(中级)操作证考试题库及模拟考试
- Fabric. JS centered element
猜你喜欢

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

The children in the deep mountains are seeing the stars farther away

SVN中的回退操作

SOA架构/测试阶段接口描述语言转换方案

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

2022年茶艺师(中级)操作证考试题库及模拟考试

重庆第一个科创板IPO,来了

单片机底层通信协议① —— 同步和异步、并行和串行、全双工和半双工以及单工、电平信号和差分信号

What should be done to improve the service level of the park and optimize the business environment

虚拟机ping不通的几种原因及解决办法
随机推荐
Who is using my server? what are you doing? when?
大山深处的孩子,正在看见更远的星空
Chongqing's first sci tech Innovation Board IPO is coming
The children in the deep mountains are seeing the stars farther away
5年后,你将如何融入20万亿美元的「项目经济」
Fabric. JS activation input box
Designing drugs with code: are we here yet?
厉害了,工信部推出 “一键解绑” 手机号绑定的互联网账号,堪称神器
成立1年便成独角兽,腾讯滴滴做「靠山」,今年新晋的独角兽不简单
Fabric. Keep the original level when JS element is selected
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
Mysql database implementation setting field length
AHK common functions
二十多年了,安全套市场还只有杜蕾斯、冈本、杰士邦
KDD 2021 | MoCl: comparative learning of molecular graphs using multi-level domain knowledge
Online communication skill network: a sparse model for solving multi task and multi-modal problems (Qingyuan talk, issue 19, tangduyu)
ahk常用函数
script 标签自带的属性
当v-if和v-for需要同时使用的时候
KDD 2021 | MoCL:利用多层次领域知识的分子图对比学习