使用matplotlib在y轴上放置正确的标签

时间:2016-12-15 06:22:30

标签: python python-3.x matplotlib yaxis

我有一个OHLC烛台图,我想在y轴上放置正确的标签,但我不能,我想把收盘价放在y轴上。这是我的代码和数据。

图表如下所示:https://i.imgsafe.org/2354d30039.jpg

  

datos_tratados.csv

     

日期时间,开放,高,低,关闭

201611010000,1.096100,1.096140,1.096100,1.096130
201611010001,1.096130,1.096200,1.096130,1.096160
201611010002,1.096150,1.096210,1.096140,1.096150
201611010003,1.096140,1.096170,1.096130,1.096140
201611010004,1.096150,1.096220,1.096150,1.096220
201611010005,1.096220,1.096320,1.096220,1.096300
201611010006,1.096300,1.096340,1.096300,1.096340
201611010007,1.096350,1.096360,1.096320,1.096340
201611010008,1.096360,1.096370,1.096350,1.096370
201611010009,1.096370,1.096410,1.096340,1.096360
201611010010,1.096360,1.096380,1.096360,1.096360
201611010011,1.096370,1.096370,1.096370,1.096370
201611010012,1.096370,1.096370,1.096300,1.096320
201611010013,1.096320,1.096390,1.096300,1.096380
201611010014,1.096380,1.096410,1.096360,1.096380
201611010015,1.096370,1.096370,1.096350,1.096360
201611010016,1.096350,1.096350,1.096320,1.096320
201611010017,1.096290,1.096300,1.096290,1.096300
201611010018,1.096320,1.096420,1.096320,1.096420
201611010019,1.096440,1.096440,1.096350,1.096370
201611010020,1.096360,1.096530,1.096340,1.096530
201611010021,1.096500,1.096520,1.096480,1.096520
201611010022,1.096510,1.096520,1.096480,1.096510
201611010023,1.096520,1.096530,1.096490,1.096520
201611010024,1.096520,1.096610,1.096520,1.096560
201611010025,1.096570,1.096790,1.096570,1.096790
201611010026,1.096770,1.096830,1.096660,1.096820
201611010027,1.096810,1.096850,1.096800,1.096810
201611010028,1.096790,1.096790,1.096680,1.096690
201611010029,1.096690,1.096700,1.096680,1.096700

代码:

from datetime import datetime
import numpy as np
from matplotlib.finance import date2num
from matplotlib import style
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick_ohlc
import matplotlib.dates as md
import matplotlib.ticker as mticker

# Generar numpy.array con los 4 datos, convirtiendo la fecha en flotante para graficar
convertir = lambda x: date2num(datetime.strptime(x.decode("utf-8"), '%Y%m%d%H%M'))
fecha, apertura, alto, bajo, cierre = np.loadtxt('datos_tratados.csv', delimiter=',', unpack=True,
                                                 converters={0: convertir})


style.use('dark_background')
plt.rc('font', size=10)
figura, ax = plt.subplots()
plt.title('EURUSD', size=15)
plt.grid(False)

ohlc = []
for i in range(len(fecha)):
    agregar = fecha[i], apertura[i], alto[i], bajo[i], cierre[i]
    ohlc.append(agregar)

# Generar el gráfico ohlc y configuraciones básicas del eje x
#plt.plot(fecha, cierre)
candlestick_ohlc(ax, ohlc, width=0.0004, colorup='lime', colordown='red')
xfmt = md.DateFormatter('%d %b %H:%M')
ax.xaxis.set_major_formatter(xfmt)

for label in ax.xaxis.get_ticklabels():
    label.set_rotation(90)

# plt.xticks(fecha)
ax.xaxis.set_major_locator(mticker.MaxNLocator(25))
plt.xlim(min(fecha) - 0.001, max(fecha) + 0.0017)
ax.yaxis.tick_right()
plt.subplots_adjust(left=0.01, bottom=0.20, right=0.94, top=0.90, wspace=0.2, hspace=0)
plt.show()

我该怎么办?

0 个答案:

没有答案