Last active
June 5, 2017 07:58
-
-
Save adxrgh/4398551b0ed47dcd24c1df6ae668273d to your computer and use it in GitHub Desktop.
plot 详解
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
import matplotlib | |
matplotlib.style.use('ggplot') ## 采用ggplot格式 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#x/y设置plot | |
%matplotlib inline | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
import numpy as np | |
x=np.linspace(-5,2,100) | |
y1=x**3+5*x**2+10 | |
y2=3*x**2+10*x | |
y3=6*x+10 | |
fig,ax=plt.subplots() | |
ax.plot(x,y1,color='black',label='y(x)') | |
ax.plot(x,y2) | |
ax.plot(x,y3) | |
ax.set_xlabel('x') | |
ax.set_ylabel('y') | |
ax.legend() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ipython -pylab | |
import matplotlib.pyplot as plt | |
fig=plt.figure() | |
plt.plot(1,1,1) | |
from matplotlib.finance import candlestick_ohlc # 蜡烛图 | |
a.xaxis_date() #a的x轴为日期 | |
plt.show() | |
每次编写代码时进行参数设置 | |
1,显示中文 | |
#coding:utf-8 | |
import matplotlib.pyplot as plt | |
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 | |
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 | |
#有中文出现的情况,需要u'内容' | |
2,时间转换为数字 | |
先从unicode str转换成datetime | |
然后再实现 | |
from matplotlib.pylab import date2num | |
··· | |
组合成为一个list | |
zip() | |
3,构建画板并设置x轴为日期 | |
fig, ax=plt.subplots() | |
```旋转日期 | |
plt.xtics(rotation=45) | |
··· | |
pplotly | |
import plotly.plotly as py | |
import plotly.graph_objs as go | |
import pandas_datareader.data as web | |
from datetime import datetime | |
df = web.DataReader("aapl", 'yahoo', datetime(2007, 10, 1), datetime(2009, 4, 1)) | |
trace = go.Candlestick(x=df.index, | |
open=df.Open, | |
high=df.High, | |
low=df.Low, | |
close=df.Close) | |
data = [trace] | |
py.iplot(data, filename='simple_candlestick') | |
###https://plot.ly/python/candlestick-charts/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment