- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个像下面这样的简单文件,上面有一些文本和数字:
some text pre 69 some text post
some text pre 63 some text post
some text pre 62 some text post
some text pre 175 some text post
some text pre 57 some text post
some text pre 59 some text post
some text pre 63 some text post
some text pre 58 some text post
some text pre 50 some text post
some text pre 45 some text post
some text pre 46 some text post
some text pre 39 some text post
some text pre 36 some text post
some text pre 39 some text post
some text pre 35 some text post
some text pre 42 some text post
some text pre 36 some text post
some text pre 35 some text post
some text pre 31 some text post
some text pre 34 some text post
some text pre 28 some text post
some text pre 110 some text post
some text pre 25 some text post
some text pre 36 some text post
some text pre 35 some text post
some text pre 21 some text post
some text pre 22 some text post
some text pre 21 some text post
some text pre 34 some text post
some text pre 32 some text post
some text pre 36 some text post
some text pre 34 some text post
some text pre 20 some text post
some text pre 18 some text post
some text pre 20 some text post
some text pre 35 some text post
some text pre 31 some text post
some text pre 35 some text post
some text pre 37 some text post
some text pre 22 some text post
some text pre 24 some text post
some text pre 19 some text post
some text pre 25 some text post
some text pre 21 some text post
some text pre 19 some text post
some text pre 20 some text post
some text pre 19 some text post
some text pre 22 some text post
some text pre 21 some text post
some text pre 20 some text post
some text pre 22 some text post
some text pre 18 some text post
some text pre 20 some text post
some text pre 21 some text post
some text pre 20 some text post
some text pre 20 some text post
some text pre 19 some text post
some text pre 21 some text post
some text pre 18 some text post
some text pre 20 some text post
some text pre 20 some text post
some text pre 20 some text post
some text pre 20 some text post
some text pre 22 some text post
some text pre 23 some text post
some text pre 20 some text post
some text pre 19 some text post
some text pre 20 some text post
some text pre 21 some text post
some text pre 22 some text post
some text pre 18 some text post
some text pre 26 some text post
some text pre 19 some text post
some text pre 20 some text post
some text pre 20 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 2 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 2 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 2 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 2 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 3 some text post
some text pre 2 some text post
some text pre 3 some text post
some text pre 3 some text post
我有 python 脚本,它将文件中的数字解析为一个数组,并根据数字数组绘制图形。简单的。以下是我的 python 脚本。
# Script 1
#!/usr/bin/env python
import re
import matplotlib.pyplot as plt
import os
import sys
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
some_text_1 = "some text pre "
some_text_2 = " some text post"
with open("/path/to/file.txt", 'r') as file:
filetext = file.read()
lines = [line for line in filetext.split('\n') if some_text_1 in line]
numbers_array = []
for x in lines:
number_in_string = find_between(x, some_text_1, some_text_2)
if number_in_string:
number = 0
number = number_in_string
numbers_array.append(number)
fig = plt.figure(num=None, figsize=(15, 9), facecolor='w', edgecolor='k')
plt.plot(numbers_array)
plt.ylabel('Learning python')
plt.show()
以下是图表的显示方式,莫名其妙的奇怪!并错误地绘制
数值较低的数字如何表示在较高的数字之上?我做错了什么?
但是,如果声明 numbers_array
并像下面修改后的脚本那样内联添加一些数字,那么图表绘制好吗?
# Script 2
#!/usr/bin/env python
import re
import matplotlib.pyplot as plt
numbers_array = [79, 66, 69, 63, 62, 175, 57, 59, 63, 58, 50, 45, 46, 39, 36, 39, 35, 42, 36, 35, 31, 34, 28,
110, 25, 36, 35, 21, 22, 21, 34, 32, 36, 34, 20, 18, 20, 35, 31, 35, 37, 22, 24, 19, 25, 21,
19, 20, 19, 22, 21, 20, 22, 18, 20, 21, 20, 20, 19, 21, 18, 20, 20, 20, 20,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3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3]
fig = plt.figure(num=None, figsize=(15, 9), facecolor='w', edgecolor='k')
plt.plot(numbers_array)
plt.ylabel('Learning python')
plt.show()
以下是当 numbers_array
用随机值硬编码时看起来正确的图。
问题:Script 1
我做错了什么?
最佳答案
问题是,在第一个脚本中你有一个字符串列表,而不是数字列表。
matplotlib 仍然没有提示的唯一原因是,它默默地建议您绘制类别而不是数字。因此,每个新元素都在下一个 y 水平上绘制,独立于其作为数字的值 - 并且该水平的命名与元素相同。
例子:
example_list = ['2', '0', '3', '4', '2', '23', '-5']
fig, axs = plt.subplots(1, 2, figsize=(10, 5))
axs[0].plot(example_list)
axs[0].set_title("plot(['2', '0', '3', '4', '2', '23', '-5'])")
axs[0].set_ylabel('categories')
axs[1].plot([int(i) for i in example_list])
axs[1].set_title('plot([2, 0, 3, 4, 2, 23, -5])')
axs[1].set_ylabel('numbers')
关于Python matplot-ting 使用数组附加的曲线奇怪地在较高位置显示较低的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57920680/
我正在尝试用 java 编写具有以下输出的 java 代码。 ---JGRASP exez: java Guess Is the number 50? H Ia the number
如果查看 Azure 存储中磁盘的定价等级(截至目前,美国东部地区的高级 SSD 低于一级),就会发现提供的 IOPS 越高,磁盘大小就越大。 人们可以选择更高的性能层,但使用较小的磁盘大小(尽管这可
如果查看 Azure 存储中磁盘的定价等级(截至目前,美国东部地区的高级 SSD 低于一级),就会发现提供的 IOPS 越高,磁盘大小就越大。 人们可以选择更高的性能层,但使用较小的磁盘大小(尽管这可
我是 azurewebsites 服务的新用户,我很高兴为什么我的网站发送了太多数据。服务器在 8 小时内输出了 55GB 数据。我的网站不包含任何大文件,它只是一个名片网站。我如何检查发生了什么?此
我希望我的 Bootstrap 轮播在图像上方有一个点覆盖。 Carousel Caption 应位于虚线叠加层之上。我无法让它与 z-indexes 一起工作。 我做错了什么吗? (可能安静 :-)
我正在使用动态编程来解决一个问题,其中我将得到 n 并且需要输出最小数量的操作以通过使用这三个操作(-1,/2,/3)从 n 中获得 1。给定约束(1 using namespace std; int
我需要在左右栏之间放置内容,前提是内容 block 高于左右栏 block 。我试着用 float: right;在内容的样式中,它只对齐图中的示例。 如何使列之间的内容 block 居中?我的代码是
我有一个非常简单的网页设置,由 div、标题和 i 元素组成的网格: 我想要做的就是在这个网格后面添加一个带有背景颜色和标题的 div,网格的元素出现在新背景 div 的顶部。 但是,当我尝试这样做时
大家,我是数据科学的新手。我正在使用支持向量回归来解决回归问题。使用网格搜索调整 SVM 参数后,我得到了 2.6% MAPE,但我的 MAE 和 MSE 仍然非常高。 我为mape使用了用户定义的函
我是一名优秀的程序员,十分优秀!