gpt4 book ai didi

Python手动定义matplotlib xlim()

转载 作者:行者123 更新时间:2023-11-28 22:38:26 34 4
gpt4 key购买 nike

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

像这样:

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

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

最佳答案

你想要 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 值数组。

关于Python手动定义matplotlib xlim(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35581192/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com