matplotlib-画图参数-日期做x轴
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time: 2020/5/25 22:02# @Author: LaoChenimport matplotlib.pyplot as pltimport datetimedef day_list():days = [1,2,3,4,5,6,7,8,9]base_date = datetime.dateti
·
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/5/25 22:02
# @Author : LaoChen
import matplotlib.pyplot as plt
import datetime
def day_list():
days = [1,2,3,4,5,6,7,8,9]
base_date = datetime.datetime(2020,1,1)
date_list = []
for i in days:
day_t = base_date + datetime.timedelta(days=i)
date_list.append(day_t)
return date_list
def plot_day():
x = day_list()
y = [2,3,5,7,9,7,5,3,2]
#设置图片大小
plt.figure(figsize=(16,8))
#设置标题
plt.title('0101')
#折线图,参数-颜色(color = 'k')-样式(linestyle = '--')-标签(label = 'x')
plt.plot(x,y,color = 'k',linestyle = '--',label = 'x')
#散点图
plt.plot(x,y,'bo')
plt.legend()
plt.show()
plot_day()
常见的颜色参数:Colors
character description
============= ===============================
``'b'`` blue 蓝
``'g'`` green 绿
``'r'`` red 红
``'c'`` cyan 蓝绿
``'m'`` magenta 洋红
``'y'`` yellow 黄
``'k'`` black 黑
``'w'`` white 白
============= ===============================
点型参数Markers,如:marker=‘o’ 只有简写,英文描述不被识别
character description
============= ===============================
``'.'`` point marker
``','`` pixel marker
``'o'`` circle marker
``'v'`` triangle_down marker
``'^'`` triangle_up marker
``'<'`` triangle_left marker
``'>'`` triangle_right marker
``'1'`` tri_down marker
``'2'`` tri_up marker
``'3'`` tri_left marker
``'4'`` tri_right marker
``'s'`` square marker
``'p'`` pentagon marker
``'*'`` star marker
``'h'`` hexagon1 marker
``'H'`` hexagon2 marker
``'+'`` plus marker
``'x'`` x marker
``'D'`` diamond marker
``'d'`` thin_diamond marker
``'|'`` vline marker
``'_'`` hline marker
============= ===============================
线型参数Line Styles,linestyle=’–’
character description
============= ===============================
``'-'`` solid line style 实线
``'--'`` dashed line style 虚线
``'-.'`` dash-dot line style 点画线
``':'`` dotted line style 点线
============= ===============================
更多推荐
已为社区贡献11条内容
所有评论(0)