【发布时间】:2015-12-11 23:35:17
【问题描述】:
我无法正确安排绘图中 X 轴上的日期标签。我放了图表图像,以便您更好地理解我的问题。
这里有创建图表的代码:
plt.figure()
x_axis = [] # contains the date value
y_axis = [] # an integer value
x_values_str = [] # contains the date representation
for data in json.loads(trend.trend_values):
date_obj = datetime.datetime.strptime(str(data[3]), '%m-%d-%Y %H:%M')
x_axis.append(dates.date2num(date_obj))
y_axis.append(str(data[2]))
x_values_str.append(str(data[3]))
plt.xticks(x_axis, x_values_str, rotation=45)
plt.plot_date(x_axis, y_axis, tz=None, xdate=True, ydate=False, linestyle='-', marker='D',color='g')
plt.title("Vowel: " + trend.vowel)
plt.margins(0.1)
plt.subplots_adjust(bottom=0.1)
所以,这里的问题是 X 值彼此之间的距离不相等。如何调整间隔? 谢谢
【问题讨论】:
-
您的问题是标签重叠,还是标签的中点与刻度线对齐?重叠是由于数据点来自同一日期,并且对齐是默认值。您是否希望数据点具有相同的距离,但标有日期?
-
@Stefan 是的,我希望数据点具有相同的距离,但标有日期。我的意思是,我希望数据点沿 x 轴均匀分布。我希望你明白我的目标:)
标签: python datetime matplotlib intervals