python中plot不能显示标签_Python Matplotlib。小阴谋。Xticks()yticks()(设置与X或Y轴对应的显示标签),pythonmatplotlibpyplotxtick...

# -*- coding: utf-8 -*-

"""

@File : 20200226_绘制平均识别数-时间图.py

@Time : 2020/2/26 10:04

@Author : Dontla

@Email : sxana@qq.com

@Software: PyCharm

"""

import re

from decimal import Decimal

import numpy as np

import matplotlib.pyplot as plt

keyword_20200225 = {'15:41': (10900, 16.94), '16:23': (11000, 16.98), '16:30': (8640, 16.40), '16:32': (7483, 16.88),

'16:39': (6482, 16.96), '16:44': (6026, 16.08), '16:55': (5887, 16.22), '16:57': (5190, 15.64),

'17:00': (4236, 15.80),

'17:05': (3153, 15.78), '17:08': (2550, 15.30), '17:10': (2016, 15.00), '17:16': (1790, 15.30),

'17:21': (2755, 16.16), '17:24': (3300, 16.84),

'17:28': (2929, 14.88), '17:32': (2507, 16.82), '17:38': (2484, 16.56), '17:47': (3018, 16.96),

'17:50': (2857, 16.94), '17:57': (2387, 16.52),

'18:00': (2012, 15.86), '18:04': (1663, 15.82), '18:10': (1200, 16.04), '18:14': (967, 15.64),

'18:18': (748, 14.98), '18:21': (623, 14.80),

'18:24': (485, 14.14), '18:26': (399, 13.08), '18:29': (316, 13.68), '18:31': (251, 13.36),

'18:33': (223, 12.96), '18:35': (200, 12.88),

'18:37': (160, 12.40), '18:38': (144, 11.96), '18:39': (129, 11.56), '18:40': (107, 11.02),

'18:41': (89, 11.10), '18:42': (72, 11.08),

'18:43': (59, 12.18), '18:44': (45, 11.22), '18:45': (38, 11.46), '18:46': (31, 11.26),

'18:47': (26, 10.68), '18:48': (21, 8.84),

'18:49': (15, 6.72), '18:50': (11, 5.60), '18:51': (9, 2.40), '18:52': (7, 0.56),

'18:53': (5, 0.00)}

time_string = []

time_extract = []

Illumination_extract = []

mean_dectect_num = []

for key in keyword_20200225:

time_string.append(key)

# 貌似用这个比re.findall()提取数字好用?

hour, minute = np.fromstring(key, dtype=int, sep=':')

time_extract.append(round(hour + minute / 60, 2))

Illumination_extract.append(keyword_20200225[key][0])

mean_dectect_num.append(keyword_20200225[key][1])

# print(time_string)

# ['15:41', '16:23', '16:30', '16:32', '16:39', '16:44', '16:55', '16:57', '17:00', '17:05', '17:08', '17:10', '17:16', '17:21', '17:24', '17:28', '17:32', '17:38', '17:47', '17:50', '17:57', '18:00', '18:04', '18:10', '18:14', '18:18', '18:21', '18:24', '18:26', '18:29', '18:31', '18:33', '18:35', '18:37', '18:38', '18:39', '18:40', '18:41', '18:42', '18:43', '18:44', '18:45', '18:46', '18:47', '18:48', '18:49', '18:50', '18:51', '18:52', '18:53']

# print(time_extract)

# [15.68, 16.38, 16.5, 16.53, 16.65, 16.73, 16.92, 16.95, 17.0, 17.08, 17.13, 17.17, 17.27, 17.35, 17.4, 17.47, 17.53, 17.63, 17.78, 17.83, 17.95, 18.0, 18.07, 18.17, 18.23, 18.3, 18.35, 18.4, 18.43, 18.48, 18.52, 18.55, 18.58, 18.62, 18.63, 18.65, 18.67, 18.68, 18.7, 18.72, 18.73, 18.75, 18.77, 18.78, 18.8, 18.82, 18.83, 18.85, 18.87, 18.88]

# print(Illumination_extract)

# [10900, 11000, 8640, 7483, 6482, 6026, 5887, 5190, 4236, 3153, 2550, 2016, 1790, 2755, 3300, 2929, 2507, 2484, 3018, 2857, 2387, 2012, 1663, 1200, 967, 748, 623, 485, 399, 316, 251, 223, 200, 160, 144, 129, 107, 89, 72, 59, 45, 38, 31, 26, 21, 15, 11, 9, 7, 5]

# 还有一种优雅一点的方法:

# time_extract = [round(np.fromstring(key, dtype=int, sep=':')[0] + np.fromstring(key, dtype=int, sep=':')[1] / 60, 2) for

# key in keyword_20200225]

# print(time_extract)

# [15.68, 16.38, 16.5, 16.53, 16.65, 16.73, 16.92, 16.95, 17.0, 17.08, 17.13, 17.17, 17.27, 17.35, 17.4, 17.47, 17.53, 17.63, 17.78, 17.83, 17.95, 18.0, 18.07, 18.17, 18.23, 18.3, 18.35, 18.4, 18.43, 18.48, 18.52, 18.55, 18.58, 18.62, 18.63, 18.65, 18.67, 18.68, 18.7, 18.72, 18.73, 18.75, 18.77, 18.78, 18.8, 18.82, 18.83, 18.85, 18.87, 18.88]

# 绘制光照度散点图

plot1 = plt.plot(time_extract, Illumination_extract, '*', label='Illumination/lx')

# 绘制平均识别个数散点图

plot2 = plt.plot(time_extract, [i * 700 for i in mean_dectect_num], 'o', label='mean dectect num × 7 × 10^2/pcs')

plt.xticks(time_extract, time_string, rotation=45, fontsize=6, verticalalignment='top', fontweight='light')

# 限制绘制上下限

# plt.ylim(-100, 12000)

plt.xlabel('Time')

plt.ylabel('Illumination & mean detect num')

plt.legend(loc=3) # 指定legend的位置,读者可以自己help它的用法

plt.title('2020/02/25 cloudy day Scatter')

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值