python画趋势图_python 绘制走势图

1.工具

matplotlib

numpy

2.matplotlib使用

import matplotlib.pyplot as plt #plt用于显示图片

import matplotlib.image as mping #mping用于读取图片

import datetime as dt

import matplotlib.dates as mdates

from pylab import *

def draw_trend_chart(dates,y):

mpl.rcParams['font.sans-serif'] = ['SimHei'] #指定默认字体

mpl.rcParams['axes.unicode_minus'] = False #解决保存图像是负号'-'显示为方块的问题

x = [dt.datetime.strptime(d,'%Y/%m/%d').date() for d in dates]

#plt.figure(figsize=(8,8))

plt.figure()

#plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y'))

#plt.gca().xaxis.set_major_locator(mdates.DayLocator())

#plt.plot(x,y,"r--",linewidth=2)

plt.plot(x,y,"r",linewidth=1)

#plt.gcf().autofmt_xdate()

#plt.xlabel("DATE"

你可能感兴趣的:(python画趋势图)