你能解释一下为什么情节在 J 处停止(在索引 10 处)
Can you explain why the plot is stopping at J (at index 10)
我是运行这个程序来查找特定文本中的字符分布。
# this is a paragraph from python documentation :)
mytext = 'When a letter is first k encountered, it is missing from the mapping, so the default_factory function calls int() to supply a default count of zero. The increment operation then builds up the count for each letter.The function int() which always returns zero is just a special case of constant functions. A faster and more flexible way to create constant functions is to use a lambda function which can supply any constant value (not just zero):'
d = dict()
ignorelist = ('(',')',' ', ',', '.', ':', '_')
for n in mytext:
if(n not in ignorelist):
n = n.lower()
if n in d.keys():
d[n] = d[n] + 1
else:
d[n] = 1
xx = list(d.keys())
yy = list(d.values())
import matplotlib.pyplot as plt
plt.scatter(xx,yy, marker = '*')
plt.show()
两个列表都有25个元素。出于某种奇怪的原因,情节是这样发生的。它在 x 轴的 'J' 处结束。
如果我缩放它,右侧会可见,但没有绘制任何点。
请注意,这将在 matplotlib 2.2 版后得到修复
您似乎在 matplotlib 2.1 的新分类功能中发现了一个错误。对于单个字母类别,它显然会将其功能限制为 10 个项目。如果类别包含更多字母,则不会发生这种情况。
无论如何,一种解决方案是绘制数值(就像在 matplotlib 2.1 之前需要做的那样)。然后将标签设置为类别。
# this is a paragraph from python documentation :)
mytext = 'When a letter is first k encountered, it is missing from the mapping, so the default_factory function calls int() to supply a default count of zero. The increment operation then builds up the count for each letter.The function int() which always returns zero is just a special case of constant functions. A faster and more flexible way to create constant functions is to use a lambda function which can supply any constant value (not just zero):'
d = dict()
ignorelist = ('(',')',' ', ',', '.', ':', '_')
for n in mytext:
if(n not in ignorelist):
n = n.lower()
if n in d.keys():
d[n] = d[n] + 1
else:
d[n] = 1
xx,yy = zip(*d.items())
import numpy as np
import matplotlib.pyplot as plt
xx_sorted, order = np.unique(xx, return_inverse=True)
plt.scatter(order,yy, marker="o")
plt.xticks(range(len(xx)), xx_sorted)
plt.show()
我是运行这个程序来查找特定文本中的字符分布。
# this is a paragraph from python documentation :)
mytext = 'When a letter is first k encountered, it is missing from the mapping, so the default_factory function calls int() to supply a default count of zero. The increment operation then builds up the count for each letter.The function int() which always returns zero is just a special case of constant functions. A faster and more flexible way to create constant functions is to use a lambda function which can supply any constant value (not just zero):'
d = dict()
ignorelist = ('(',')',' ', ',', '.', ':', '_')
for n in mytext:
if(n not in ignorelist):
n = n.lower()
if n in d.keys():
d[n] = d[n] + 1
else:
d[n] = 1
xx = list(d.keys())
yy = list(d.values())
import matplotlib.pyplot as plt
plt.scatter(xx,yy, marker = '*')
plt.show()
两个列表都有25个元素。出于某种奇怪的原因,情节是这样发生的。它在 x 轴的 'J' 处结束。
如果我缩放它,右侧会可见,但没有绘制任何点。
请注意,这将在 matplotlib 2.2 版后得到修复
您似乎在 matplotlib 2.1 的新分类功能中发现了一个错误。对于单个字母类别,它显然会将其功能限制为 10 个项目。如果类别包含更多字母,则不会发生这种情况。
无论如何,一种解决方案是绘制数值(就像在 matplotlib 2.1 之前需要做的那样)。然后将标签设置为类别。
# this is a paragraph from python documentation :)
mytext = 'When a letter is first k encountered, it is missing from the mapping, so the default_factory function calls int() to supply a default count of zero. The increment operation then builds up the count for each letter.The function int() which always returns zero is just a special case of constant functions. A faster and more flexible way to create constant functions is to use a lambda function which can supply any constant value (not just zero):'
d = dict()
ignorelist = ('(',')',' ', ',', '.', ':', '_')
for n in mytext:
if(n not in ignorelist):
n = n.lower()
if n in d.keys():
d[n] = d[n] + 1
else:
d[n] = 1
xx,yy = zip(*d.items())
import numpy as np
import matplotlib.pyplot as plt
xx_sorted, order = np.unique(xx, return_inverse=True)
plt.scatter(order,yy, marker="o")
plt.xticks(range(len(xx)), xx_sorted)
plt.show()