Python手动定义matplotlib xlim()

时间:2016-02-23 15:14:11

标签: python matplotlib

我想在xlim([])中放置一个单词数组来代替一系列数字。使用普通的python和matplotlib。

像这样:

ax.set_xlim(['week1', 'week2', 'week3', 'week4', 'week5', 'week6', 'week7', 'week8', 'week9', 'week10'])

实现这一目标的最佳方法是什么?

1 个答案:

答案 0 :(得分:4)

你想要matplotlib.pyplot.xticks。类似的东西:

# set the locations and labels of the xticks
plt.xticks( arange(10), ('week1', 'week2', 'week3', 'week4', 'week5', 'week6', 'week7', 'week8', 'week9', 'week10') )

而不是arange(10),您需要数据的x值数组。