首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数据可视化Python

数据可视化Python
EN

Stack Overflow用户
提问于 2019-10-15 05:01:18
回答 1查看 169关注 0票数 0
  1. 为这4家公司绘制了4幅不同的线图( dataframe open_prices )。年在X轴上,股票价格在Y轴上,你需要(2,2)地块.将图形大小设置为10,8并共享X轴,以便更好地进行可视化。

从nsepy导入numpy作为np导入matplotlib.pyplot作为plt从nsepy导入get_history导入日期时间( dt %matplotlib inline = dt.datetime(2015,1,1) end = dt.datetime.today() infy =get_history(符号=‘INFY’,start = start,end = end) infy.index = pd.to_datetime(infy.index) hdfc =get_history(符号=‘HDFC’,start = start,结束) hdfc.index = pd.to_datetime(hdfc.index)依赖=get_history(符号=‘依赖’,开始=开始,reliance.index = pd.to_datetime(reliance.index) wipro =get_history(符号= 'Wipro‘,start = start,end = end) wipro.index = pd.to_datetime(wipro.index) open_prices =pd.concat([Infy’‘Open’,Hdfc‘’Open‘,信实’开放‘,Wipro’‘Open’],轴= 1) open_prices.columns = 'Infy','Hdfc',‘信实’,‘Wipro’f,(ax1,ax2) = plt.subplots(1,2,sharey=True) axes0,地块(open_prices.index.year,open_prices.INFY) axes0,情节(open_prices.index.year,open_prices.HDB) axes1,0 plot(open_prices.index.year,open_prices.TTM) axes1,1 plot(open_prices.index.year,open_prices.HDB)axes1

空白图是coming.Please帮助.?

EN

回答 1

Stack Overflow用户

发布于 2019-10-15 08:42:48

下面的代码工作正常,我已经更改了以下内容

( a)轴应该是ax,b) DF列名是不正确的,c)任何尝试这个例子的人都需要安装lxml库

代码语言:javascript
复制
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from nsepy import get_history
import datetime as dt

start = dt.datetime(2015, 1, 1)
end = dt.datetime.today()
infy = get_history(symbol='INFY', start = start, end = end)
infy.index = pd.to_datetime(infy.index)
hdfc = get_history(symbol='HDFC', start = start, end = end)
hdfc.index = pd.to_datetime(hdfc.index)
reliance = get_history(symbol='RELIANCE', start = start, end = end)
reliance.index = pd.to_datetime(reliance.index)
wipro = get_history(symbol='WIPRO', start = start, end = end)
wipro.index = pd.to_datetime(wipro.index)
open_prices = pd.concat([infy['Open'], hdfc['Open'],reliance['Open'],
wipro['Open']], axis = 1)
open_prices.columns = ['Infy', 'Hdfc', 'Reliance', 'Wipro']
print(open_prices.columns)

ax=[]
f, ax = plt.subplots(2, 2, sharey=True)
ax[0,0].plot(open_prices.index.year,open_prices.Infy)
ax[1,0].plot(open_prices.index.year,open_prices.Hdfc)
ax[0,1].plot(open_prices.index.year,open_prices.Reliance)
ax[1,1].plot(open_prices.index.year,open_prices.Wipro)
plt.show()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58387520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档