第一个变量在nparange(x,y,z)中做什么?

时间:2019-06-20 22:01:35

标签: python python-3.x numpy

所以我正在学习使用matplotlib制作图形,但我真的不太了解numpy。设置我的yticks时,我使用的是np.arange(0,80000,10000),但我想不出第一个变量的用途,有人可以帮我吗?

我尝试将变量更改为更大的数字,我唯一注意到的是更长的加载时间和CPU的负担越来越重。

import matplotlib
import numpy as np
import matplotlib.pyplot as plt


N = 6
catPopulation = (20000, 35000, 30000, 35000, 27000, 33000)
dogPopulation = (25000, 32000, 34000, 20000, 25000, 33000)
ind = np.arange(N)  
width = 0.11       

p1 = plt.bar(ind, catPopulation, width)
p2 = plt.bar(ind, dogPopulation, width,
             bottom=catPopulation)

plt.ylabel('Population Per City')
plt.title('Comparing Cat and Dog Populations For Different Cities')
plt.xticks(ind, ('Houston', 'Detroid', 'Chicago', 'Los Angelos', 'New York', 'Sacramento'))
plt.yticks(np.arange(0, 80000, 10000))
plt.legend((p1[0], p2[0]), ('Cats', 'Dogs'))
plt.show()

2 个答案:

答案 0 :(得分:3)

根据numpy's documentation,arange的签名为:

numpy.arange([start, ]stop, [step, ]dtype=None)

因此,您的三个数字是: 开始:0 停止:80000 步骤:10000

因此,从0到80,000,每10,000步进。此数组is the first argument for yticks

yticks(ticks, [labels], **kwargs)  # Set locations and labels

答案 1 :(得分:-1)

弄清楚了,这是计数的起点。