将x_axis从数字更改为月份

时间:2018-05-06 15:33:55

标签: python-3.x matplotlib plot

我有以下情节: image 1 here x_axis是数字的年份(从1到365)

我想将x_axis更改为以下内容: image 2 here

我该怎么做?

1 个答案:

答案 0 :(得分:0)

试试这个:

import matplotlib.pyplot as plt
import numpy as np

# Data
x = np.array([0,15,30,45,60,75,90]) # Days
y = np.array([20,25,21,22,23,20,29]) # Temperature

# Labels
first_day_of_month = np.array([0,31,59,89]) # First day of each month
my_xticks = ['January','February','March','April']
plt.xticks(first_day_of_month, my_xticks)

#Plot
plt.plot(x, y)
plt.show()

Example

相关问题