matplotlib命令与格式:tick_params参数刻度线样式设置

matplotlib命令与格式:tick_params参数刻度线样式设置
原文:https://blog.csdn.net/helunqu2017/article/details/78736554

import csv
import matplotlib.pyplot as plt
from datetime import datetime

file_path = r'E:\workplace\python\code\csvcsv\death_valley_2014.csv'
highs, lows, dates = [], [], []

with open(file_path, encoding='UTF-8') as f_csv:
    reader = csv.reader(f_csv)
    header = next(f_csv)

    for row in reader:
        try:
            high = int(row[1])
            low = int(row[3])
            current_date = datetime.strptime(row[0], "%Y-%m-%d")
        except ValueError:
            print(str(current_date)+ " : missing")
        finally:
            highs.append(high)
            lows.append(low)
            dates.append(current_date)

plt.plot(dates, highs, color='r', alpha=0.5)
plt.plot(dates, lows, color='b', alpha=0.5)
plt.fill_between(dates, highs, lows, facecolor='b', alpha=0.1)

# tick_params参数
# 参数axis 选择坐标轴,both/x/y
# 参数which的值为 'major'、'minor'、'both',分别代表设置主刻度线、副刻度线以及同时设置,默认值为'major'
# 参数direction的值为'in'、'out'、'inout',分别代表刻度线显示在绘图区内侧、外侧以及同时显示
# 参数labelsize用于设置刻度线标签的字体大小
# 参数bottom, top, left, right的值为布尔值,分别代表设置绘图区四个边框线上的的刻度线是否显示
# 参数labelbottom, labeltop, labelleft, labelright的值为布尔值,分别代表设置绘图区四个边框线上的刻度线标签是否显示
plt.tick_params(which='major', labelsize=16, colors="red", direction='in')
plt.show()

发布了57 篇原创文章 · 获赞 12 · 访问量 7719

猜你喜欢

转载自blog.csdn.net/volunteer1024/article/details/99175145