所以我经历了堆栈溢出,并使用了其他帖子中的解决方案。但无论我尝试什么,我的勾号总是保持为int,不采用我渴望的datetime格式。任何帮助都将不胜感激!
from datetime import datetime, time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import ticker
import mpl_finance
import MySQLdb
def isolated_candle_graph():
#Access my database
conn = MySQLdb.connect(host='localhost',
user='root',
passwd='*******',#
db='********') # falsified information
cursor = conn.cursor()
sql = "SELECT * FROM ddr"
cursor.execute(sql)
result = cursor.fetchall()
df = pd.DataFrame(list(result), columns=["Date", "Open", "High","Low", "Close", "Adj_Close", "Volume"])
fig, ax = plt.subplots()
#the plot
mpl_finance.candlestick2_ohlc(ax, df.Open, df.High, df.Low, df.Close,
width=0.6, colorup='r', colordown='c', alpha=1)
xdate = df.index
def mydate(x, pos):
try:
return xdate[int(x)]
except IndexError:
return ''
ax.xaxis.set_major_formatter(ticker.FuncFormatter(mydate))
plt.show()
isolated_candle_graph()
谢谢!
这就是我一直关注的。
matplotlib.finance.candlestick\u ohlc绘制日内1分钟条形图数据,每小时显示一次时间间隔和适当的Xticklabel
暂无答案!
目前还没有任何答案,快来回答吧!