- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在绘制一些图,然后我收到以下代码的上述错误:
lag = range(0, 31)
djia_acf = []
for l in lag:
djia_acf.append(djia_df['Close'].autocorr(l))
plt.figure(figsize = (5.5, 5.5))
g = sns.pointplot(x=lag, y=djia_acf, markers = '.')
g.set_title('Autocorrelation function for DJIA')
g.set_xlabel('Lag in terms of number of trading days')
g.set_ylabel('Autocorrelation Function')
g.set_xticklabels(lag, rotation = 90)
TypeError Traceback (most recent call last)
<ipython-input-42-3ca28bdcaeea> in <module>()
1 plt.figure(figsize = (5.5, 5.5))
----> 2 g = sns.pointplot(x=lag, y=djia_acf, markers = '.')
3 g.set_title('Autocorrelation function for DJIA')
4 g.set_xlabel('Lag in terms of number of trading days')
5 g.set_ylabel('Autocorrelation Function')
/home/aspiring1/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in pointplot(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, orient, color, palette, ax, errwidth, capsize, **kwargs)
3065 estimator, ci, n_boot, units,
3066 markers, linestyles, dodge, join, scale,
-> 3067 orient, color, palette, errwidth, capsize)
3068
3069 if ax is None:
/home/aspiring1/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, orient, color, palette, errwidth, capsize)
1607 """Initialize the plotter."""
1608 self.establish_variables(x, y, hue, data, orient,
-> 1609 order, hue_order, units)
1610 self.establish_colors(color, palette, 1)
1611 self.estimate_statistic(estimator, ci, n_boot)
/home/aspiring1/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
201 # Group the numeric data
202 plot_data, value_label = self._group_longform(vals, groups,
--> 203 group_names)
204
205 # Now handle the hue levels for nested ordering
/home/aspiring1/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in _group_longform(self, vals, grouper, order)
243
244 # Group the val data
--> 245 grouped_vals = vals.groupby(grouper)
246 out_data = []
247 for g in order:
/home/aspiring1/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, **kwargs)
4269 return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
4270 sort=sort, group_keys=group_keys, squeeze=squeeze,
-> 4271 **kwargs)
4272
4273 def asfreq(self, freq, method=None, how=None, normalize=False,
/home/aspiring1/anaconda3/lib/python3.6/site-packages/pandas/core/groupby.py in groupby(obj, by, **kwds)
1624 raise TypeError('invalid type: %s' % type(obj))
1625
-> 1626 return klass(obj, by, **kwds)
1627
1628
/home/aspiring1/anaconda3/lib/python3.6/site-packages/pandas/core/groupby.py in __init__(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, **kwargs)
390 level=level,
391 sort=sort,
--> 392 mutated=self.mutated)
393
394 self.obj = obj
/home/aspiring1/anaconda3/lib/python3.6/site-packages/pandas/core/groupby.py in _get_grouper(obj, key, axis, level, sort, mutated)
2636 sort=sort,
2637 in_axis=in_axis) \
-> 2638 if not isinstance(gpr, Grouping) else gpr
2639
2640 groupings.append(ping)
/home/aspiring1/anaconda3/lib/python3.6/site-packages/pandas/core/groupby.py in __init__(self, index, grouper, obj, name, level, sort, in_axis)
2418 t = self.name or str(type(self.grouper))
2419 raise ValueError("Grouper for '%s' not 1-dimensional" % t)
-> 2420 self.grouper = self.index.map(self.grouper)
2421 if not (hasattr(self.grouper, "__len__") and
2422 len(self.grouper) == len(self.index)):
/home/aspiring1/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in map(self, mapper)
2725 """
2726 from .multi import MultiIndex
-> 2727 mapped_values = self._arrmap(self.values, mapper)
2728 attributes = self._get_attributes_dict()
2729 if mapped_values.size and isinstance(mapped_values[0], tuple):
pandas/_libs/algos_common_helper.pxi in pandas._libs.algos.arrmap_int64 (pandas/_libs/algos.c:41758)()
TypeError: 'range' object is not callable
<matplotlib.figure.Figure at 0x7f1fa7c2ab70>
在上面的代码中,我只是尝试使用seaborn绘制点图,但它给出了范围对象不可调用的错误,我见过类似的帖子,其中有错误
"list object is not callable"
但是,在这里我看不到我的范围对象 lag 被调用的任何地方。使用 x = np.array(lag) 为我提供了所需的图,并附加了以下输出,不知道为什么?
[<matplotlib.text.Text at 0x7f1fa7d38208>,
<matplotlib.text.Text at 0x7f1fa7d38ef0>,
<matplotlib.text.Text at 0x7f1fa7c61208>,
<matplotlib.text.Text at 0x7f1fa7c61cc0>,
<matplotlib.text.Text at 0x7f1fa7c696d8>,
<matplotlib.text.Text at 0x7f1fa7c711d0>,
<matplotlib.text.Text at 0x7f1fa7c71c88>,
<matplotlib.text.Text at 0x7f1fa7c75780>,
<matplotlib.text.Text at 0x7f1fa7c7c278>,
<matplotlib.text.Text at 0x7f1fa7c7cd30>,
<matplotlib.text.Text at 0x7f1fa7c02828>,
<matplotlib.text.Text at 0x7f1fa7c08320>,
<matplotlib.text.Text at 0x7f1fa7c08dd8>,
<matplotlib.text.Text at 0x7f1fa7c0c8d0>,
<matplotlib.text.Text at 0x7f1fa7c123c8>,
<matplotlib.text.Text at 0x7f1fa7c12e80>,
<matplotlib.text.Text at 0x7f1fa7c1a978>,
<matplotlib.text.Text at 0x7f1fa7c1e470>,
<matplotlib.text.Text at 0x7f1fa7c1ef28>,
<matplotlib.text.Text at 0x7f1fa7c25a20>,
<matplotlib.text.Text at 0x7f1fa7c2a518>,
<matplotlib.text.Text at 0x7f1fa7c2afd0>,
<matplotlib.text.Text at 0x7f1fa7c31ac8>,
<matplotlib.text.Text at 0x7f1fa7c385c0>,
<matplotlib.text.Text at 0x7f1fa7c3d0b8>,
<matplotlib.text.Text at 0x7f1fa7c3db70>,
<matplotlib.text.Text at 0x7f1fa7bc5668>,
<matplotlib.text.Text at 0x7f1fa7bc9160>,
<matplotlib.text.Text at 0x7f1fa7bc9c18>,
<matplotlib.text.Text at 0x7f1fa7bce710>,
<matplotlib.text.Text at 0x7f1fa7bd4208>]
我使用 matplotlib.pyplot 绘制了绘图,它将范围对象作为 x 值,如下所示:
inflation = pd.read_excel('inflation-consumer-prices-annual.xlsx', parse_dates=['Year'])
plt.figure(figsize=(5.5, 5.5))
plt.plot(range(1960,2017), inflation['India'], linestyle='-', marker='*',
color='r')
plt.plot(range(1960,2017), inflation['United States'], linestyle='-',
marker='.', color='b')
plt.legend(['India','United States'], loc=1)
plt.title('Inflation in Consumer Price Index')
plt.ylabel('Inflation')
plt.xlabel('Years')
因此,我不知道为什么会收到 TypeError,因为它与 matplotlib.pyplot 一起使用,并且被调用的范围对象没有任何意义。
最佳答案
在 python 3 中,range
返回一个迭代器,而不是列表本身。因此,以下内容不适用于 python 3。但是,它适用于 python 2。
import seaborn as sns
import matplotlib.pyplot as plt
x = range(9)
y = [1,2,3]*3
sns.pointplot(x=x, y=y, markers = '.')
plt.show()
但是,您可以通过 list(range(...))
将任何范围
转换为列表。因此,以下工作正常。
import seaborn as sns
import matplotlib.pyplot as plt
x = list(range(9))
y = [1,2,3]*3
sns.pointplot(x=x, y=y, markers = '.')
plt.show()
关于python - 类型错误 : 'range' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53574197/
我创建了以下 sub 来简单地说明问题。我将事件工作表的范围 A2:E10 分配给范围变量。然后,对于另一个范围变量,我将这个范围的子范围,单元格 (1, 1) 分配给 (3, 3)。 我原以为这将包
我使用正则表达式来搜索以下属性返回的纯文本: namespace Microsoft.Office.Interop.Word { public class Range {
我正在开发一个宏来突出显示某些行/单元格以供进一步审查。一些值/空白将以红色突出显示,其他以橙色突出显示,而整行应为黄色。我从上一个问题中得到了一些帮助,并添加了更多细节,它工作得几乎完美,但我被困在
这个问题在这里已经有了答案: What is the difference between range and xrange functions in Python 2.X? (28 个答案) 关闭
我在尝试运行脚本时遇到这个奇怪的错误,代码似乎是正确的,但似乎 python (3) 不喜欢这部分: def function(x): if int
我正在编写一种算法,将一些数据写入提供的输出范围(问题的初始文本包括具体细节,这将评论中的讨论转向了错误的方向)。我希望它在 API 中尽可能接近标准库中的其他范围算法。 我查看了 std::rang
这按预期工作: #include #include int main() { auto chunklist = ranges::views::ints(1, 13) | ranges::vie
我这里有一个字符串,我正在尝试对其进行子字符串化。 let desc = "Hello world. Hello World." var stringRange = 1..' 的值转换为预期的参数类型
我有一个高级搜索功能,可以根据日期和时间查询记录。我想返回日期时间范围内的所有记录,然后从该范围内返回我想将结果缩小到一个小时范围(例如 2012 年 5 月 1 日 - 2012 年 5 月 7 日
Go 中的 range 函数和 range 关键字有什么区别? func main(){ s := []int{10, 20, 30, 40, 50, 60, 70, 80, 90}
如果我有一个范围,如何将其拆分为一系列连续的子范围,其中指定了子范围(存储桶)的数量?如果没有足够的元素,则应省略空桶。 例如: splitRange(1 to 6, 3) == Seq(Range(
我正在开发 VSTO Excel 项目,但在管理 Range 对象时遇到一些问题。 实际上,我需要知道当前选定的范围是否与我存储在列表中的另一个范围重叠。所以基本上,我有 2 个 Range 实例,我
在即将推出的 C++20 系列中,将有 range concept具有以下定义: template concept range = __RangeImpl; // exposition-only de
希望有人能回答我的问题。我在 VHDL 代码中遇到了这个命令,但不确定它到底做了什么。有人可以澄清以下内容吗? if ( element1 = (element1'range => '0')) the
可以将范围嵌套在范围中吗?使用范围内的变量?因为我想取得一些效果。为了说明这个问题,我有以下伪代码: for i in range(str(2**i) for i in range(1,2)):
我想在 2 个日期之间创建一个范围,并且我的范围字段有时间 damage_list = Damage.objects.filter(entry_date__range=(fdate, tdate))
在下面的代码中 #include #include #include int main() { std::unordered_mapm; m["1"]=1; m["2"]=2
我试图为我的电子表格做一个简单的循环,它循环遍历一个范围并检查该行是否为空,如果不是,则循环遍历一系列列并检查它们是否为空,如果是则它设置一个消息。 问题是每次它通过循环 ro.value 和 col
我在将一个工作簿范围中的值分配给当前工作簿中的某个范围时遇到问题。当我使用 Range("A1:C1") 分配我的范围时,此代码工作正常,但是当我使用 Range(Cells(1,1),Cells(1
我改写了原来的问题。 Sub s() Dim r As Range Set r = ActiveSheet.Range("B2:D5") Debug.Print r.Rows.Count
我是一名优秀的程序员,十分优秀!