在MatplotLib中更改和更改折线图中的x和y轴范围

时间:2018-07-03 07:52:56

标签: python pandas matplotlib charts linegraph

enter image description here enter image description here

我在图像1中创建了一个折线图,而我想将x轴(一年的365天更改为12个月),但是需要绘制每个日期的值。我想开发一个像2的图形。 我的数据框看起来像这样

       Month       Date   max   min
0      1.0 1900-01-01  15.6 -16.0
1      1.0 1900-01-02  13.9 -26.7
2      1.0 1900-01-03  13.3 -26.7
3      1.0 1900-01-04  10.6 -26.1
4      1.0 1900-01-05  12.8 -15.5

2 个答案:

答案 0 :(得分:0)

没有代码和尝试,我们无法为您提供修复。 但是,使用MatplotLib,您正在寻找的功能是:

该文档应为您提供帮助的示例:

 xticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))

# np.arange(5) is the location, i.e. 0, 1, 2, 3, 4
# ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') are the labels

编辑::由于您是在数据框中存储数据,因此您可以做一个字典来将数字转换为月份:

month = {1: "January", 2: "February", ..., 12: "December"}

答案 1 :(得分:0)

为此目的使用重采样,请执行以下操作:

visibility:hidden

除了.last()之外,您还可以使用多种其他方式,例如.min().max().mean()等,它们将相应地获取值

文档为here

相关问题