2016-12-30 123 views
3

我绘制如下图:matplotlib - 旋转次刻度

enter image description here

用下面的代码:

fig, ax = plt.subplots(figsize=(20, 3)) 
mpf.candlestick_ohlc(ax,quotes, width=0.01) 
ax.xaxis_date() 
ax.xaxis.set_minor_locator(mpl.dates.HourLocator(interval=4)) 
ax.xaxis.set_minor_formatter(mpl.dates.DateFormatter('%H:%M')) 
plt.xticks(rotation = 90) 

plt.grid(True) 
plt.show() 

我想也旋转次刻度:我会怎么做那?

子公司的问题是有没有办法转动通过一个命令主要和次要刻度?

回答

2

您可以通过一行plt.setp(ax.xaxis.get_minorticklabels(), rotation=90)代码旋转。

+0

哦!这是非常容易和清晰。 – Lucas

1

通过探索了一下,我发现ax.get_xminorticklabels()是一个text类元素的列表。

>>> print(type(ax.get_xminorticklabels()[0])) 
<class 'matplotlib.text.Text'> 

而且text可以rotated

>>> for text in ax.get_xminorticklabels(): 
>>>  text.set_rotation(90) 

xminorticklabels_rotate_example

你只需要小心,他们不重叠。