Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将价格绘制为非零体积值的水平线_Python_Python 3.x_Pandas_Matplotlib - Fatal编程技术网

Python 将价格绘制为非零体积值的水平线

Python 将价格绘制为非零体积值的水平线,python,python-3.x,pandas,matplotlib,Python,Python 3.x,Pandas,Matplotlib,我的代码: import matplotlib.pyplot as plt plt.style.use('seaborn-ticks') import pandas as pd import numpy as np path = 'C:\\File\\Data.txt' df = pd.read_csv(path, sep=",") df.columns = ['Date','Time','Price','volume'] df = df[df.Date == '08/02/2019'].re

我的代码:

import matplotlib.pyplot as plt
plt.style.use('seaborn-ticks')
import pandas as pd
import numpy as np

path = 'C:\\File\\Data.txt'
df = pd.read_csv(path, sep=",")
df.columns = ['Date','Time','Price','volume']
df = df[df.Date == '08/02/2019'].reset_index(drop=True)
df['Volume'] = np.where((df.volume/1000) < 60, 0, (df.volume/1000))

df.plot('Time','Price')

dff = df[df.Volume > 60].reset_index(drop=True)
dff = dff[['Date','Time','Price','Volume']]
print(dff)

plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95, wspace=None, hspace=None)
plt.show()
我想根据下图将此表的价格绘制为垂直线。任何帮助


根据你的形象,我认为你指的是水平线。无论哪种方式,它都非常简单,Pyplot有/内置。在你的情况下,试试类似的方法

plt.hlines(dff['Price'], '08/02/2019', '09/02/2019') 

添加了行,但没有得到输出。您是在plt.show之前添加的吗?根本没有输出?x轴的值是多少?它是df数据帧的时间
plt.hlines(dff['Price'], '08/02/2019', '09/02/2019') 
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

path = 'File.txt'
df = pd.read_csv(path, sep=",")
df.columns = ['Date','Time','Price','volume']
df = df[df.Date == '05/02/2019'].reset_index(drop=True)
df['Volume'] = np.where((df.volume/7500) < 39, 0, (df.volume/7500))
df["Time"] = pd.to_datetime(df['Time'])

df.plot(x="Time",y='Price', rot=0)

plt.title("Date: " + str(df['Date'].iloc[0]))

dff = df[df.Volume > 39].reset_index(drop=True)
dff = dff[['Date','Time','Price','Volume']]
print(dff)

dict = dff.to_dict('index')
for x in range(0, len(dict)):
    plt.axhline(y=dict[x]['Price'],linewidth=2, color='blue')

plt.subplots_adjust(left=0.05, bottom=0.06, right=0.95, top=0.96, wspace=None, hspace=None)
plt.show()