[英]How can plot 200 rows (time series) in matplotlib and make it readable in the x-axis?
Hey guys this is my code.嘿伙计们,这是我的代码。
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
banco=pd.read_csv('banco central3.csv',index_col='Fecha',parse_dates=['Fecha'], usecols=.
['RRII','Fecha'])
print(banco.head())
fig, ax = plt.subplots(figsize=(10, 10))
ax.bar(banco.index.values,
banco['RRII'],
color='purple')
ax.xaxis.set_major_locator(mdates.WeekdayLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%Y'))
ax.set(xlabel="DATE",
ylabel="RRII",
title="\nReservas Internacionales")
plt.tight_layout()
plt.show()
The output, as a plot, is the following.作为绘图的输出如下。 The data (x-axis) is unreadable.数据(x 轴)不可读。
The datetime('Fecha') is about 200 rows. datetime('Fecha') 大约有 200 行。 I want to clarity the X axis to become it readable.我想澄清 X 轴以使其可读。
and also i dont know why the barplot looks in that way (so separated among them).而且我也不知道为什么条形图看起来那样(在它们之间如此分离)。 I want a classic barplot.我想要一个经典的条形图。
You see that the datatime is unreadable你看到数据时间不可读
the format of the data is this:数据的格式是这样的:
RRII
Fecha
2019-11-27 43.765
2019-11-28 43.736
2019-11-29 43.772
2019-02-12 43.731
2019-03-12 43.750
But i have 200 rows.但我有 200 行。
There is any way of making it?有什么制作方法吗? Thanks you very much非常感谢你
EDIT编辑
I change the mdates.Daylocator to the m.dates.Monthlocator.我将 mdates.Daylocator 更改为 m.dates.Monthlocator。 and i added a Plt.setp function.我添加了一个 Plt.setp 函数。 Now my plot is not overlap but the line plot has no sense.现在我的情节不重叠但线图没有意义。
ax.xaxis.set_major_locator(mdates.MonthLocator())
plt.setp(ax.get_xticklabels(), rotation=30,
horizontalalignment='right')
IMAGE HERE.图像在这里。 I want the plot follow the RRII by datetime我希望情节按照日期时间遵循 RRII
To make the x axis readable, change the line要使 x 轴可读,请更改行
ax.xaxis.set_major_locator(mdates.WeekdayLocator())
to到
ax.xaxis.set_major_locator(mdates.MonthLocator())
However, the usage of barplot is not advisable with 200 rows;但是,对于 200 行,不建议使用 barplot; use a normal plot:使用普通图:
ax.plot(banco['RRII'], '.', color='purple')
[edit: changed marker from line point] [编辑:从线点更改标记]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.