- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
我的 Python 代码有问题。我将一个物理项目的一些测试结果写入了一个 csv 文件。然后,我编写了一个 Python 脚本,该脚本使用 matplotlib 在图表中展示结果。基本上,我有 10 个不同的系列(例如位置、速度、加速度和秒),我希望它们在一个图中。
但问题是:它完全改变了我的 Y 轴值,我不知道为什么。我只想要一个从 -1
到 1
的静态 Y 轴,然后填充不同的值。 X轴很好;这些是我的秒数。
我用 plt.axis
和 plt.axes
尝试了一些东西,但我真的被困在这里了。这是我正在谈论的代码片段:
import csv
import sys
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as tick
positionM1 = []
positionM2 = []
velocityM1 = []
velocityM2 = []
accel1 = []
accel2 = []
sec = []
forceM1 = []
forceM2 = []
federPressed = []
with open("filename", 'r') as csvfile:
plots= csv.reader(csvfile, delimiter=',')
for row in plots:
sec.append((row[0]))
velocityM1.append((row[1]))
velocityM2.append((row[2]))
positionM1.append((row[3]))
positionM2.append((row[4]))
accel1.append((row[5]))
accel2.append((row[6]))
forceM1.append((row[7]))
forceM2.append((row[8]))
federPressed.append((row[9]))
plt.axis('normal')
plt.plot(sec, velocityM1, 'b', sec, velocityM2, 'g', sec, positionM1, 'r')
plt.plot(sec, velocityM2, label="VelocityM2")
plt.plot(sec, positionM1, label="PositionM1")
plt.plot(sec, positionM2, label="PositionM2")
plt.plot(sec, accel1, label="AccelerationM1")
plt.plot(sec, accel2, label="AccelerationM2")
plt.plot(sec, forceM1, label="Newton M1")
plt.plot(sec, forceM2, label="Newton M1")
plt.plot(sec, federPressed, label="Feder gepresst")
plt.legend(fontsize=10)
plt.grid('True')
plt.show()
这是 CSV 文件:
0.0000,0.5000,0.0000,0.0000,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.0250,0.5000,0.0000,0.0125,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.0500,0.5000,0.0000,0.0250,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.0750,0.5000,0.0000,0.0375,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.1000,0.5000,0.0000,0.0500,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.1250,0.5000,0.0000,0.0625,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.1500,0.5000,0.0000,0.0750,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.1750,0.5000,0.0000,0.0875,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.2000,0.5000,0.0000,0.1000,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.2250,0.5000,0.0000,0.1125,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.2500,0.5000,0.0000,0.1250,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.2750,0.5000,0.0000,0.1375,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.3000,0.5000,0.0000,0.1500,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.3250,0.5000,0.0000,0.1625,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.3500,0.5000,0.0000,0.1750,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.3750,0.5000,0.0000,0.1875,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.4000,0.5000,0.0000,0.2000,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.4250,0.4500,0.0500,0.2113,0.3012,-2.0000,2.0000,-1.0000,1.0000,0.1000,
0.4500,0.4050,0.0950,0.2214,0.3036,-1.8000,1.8000,-0.9000,0.9000,0.0900,
0.4750,0.3639,0.1361,0.2305,0.3070,-1.6450,1.6450,-0.8225,0.8225,0.0822,
0.5000,0.3256,0.1744,0.2386,0.3114,-1.5311,1.5311,-0.7656,0.7656,0.0766,
0.5250,0.2892,0.2108,0.2458,0.3167,-1.4555,1.4555,-0.7278,0.7278,0.0728,
0.5500,0.2538,0.2462,0.2522,0.3228,-1.4163,1.4163,-0.7082,0.7082,0.0708,
0.5750,0.2185,0.2815,0.2576,0.3299,-1.4125,1.4125,-0.7063,0.7063,0.0706,
0.6000,0.1824,0.3176,0.2622,0.3378,-1.4440,1.4440,-0.7220,0.7220,0.0722,
0.6250,0.1446,0.3554,0.2658,0.3467,-1.5116,1.5116,-0.7558,0.7558,0.0756,
0.6500,0.1042,0.3958,0.2684,0.3566,-1.6170,1.6170,-0.8085,0.8085,0.0809,
0.6750,0.0601,0.4399,0.2699,0.3676,-1.7629,1.7629,-0.8814,0.8814,0.0881,
0.7000,0.0113,0.4887,0.2702,0.3798,-1.9528,1.9528,-0.9764,0.9764,0.0976,
我无法在此图中定位轴标签。我喜欢放置顶部标签,使管道与网格对齐,并放置左右标签,以便它们不接触绘图。 我试过了 ax.tick_params(axis='both', which='both'
我使用的是 python 2,下面的代码只是使用了一些示例数据,我的实际数据可能有不同的长度,并且可能不是很细。 import numpy as np import datetime i
给定坐标 [1,5,7,3,5,10,3,6,8]为 matplotlib.pyplot ,如何突出显示或着色线条的不同部分。例如,列表中的坐标 1-3 ( [1,5,7,3] ) 表示属性 a .我
我正在matplotlib中绘制以下图像。 我的问题是,图像看起来像这样,但是,我想使背景变暗,因为当我打印该图像时,灰度部分不会出现在打印物中。有人可以告诉我API进行此更改吗? 我使用简单的API
这是关于matplotlib的一个非常基本的问题,但是我不知道该怎么做: 我想绘制多个图形,并使用绘制窗口中的箭头从一个移到另一个。 目前,我只知道如何创建多个图并将其绘制在不同的窗口中,如下所示:
在 matplotlib 中绘制小块对象时,由于显示分辨率而引入了伪影。使用抗锯齿并不能解决问题。 这个问题有解决方案吗? import matplotlib.pyplot as plt impo
对于直方图,有一个简单的内置选项 histtype='step' .如何制作相同风格的条形图? 最佳答案 [阅读评论后添加答案] 将可选关键字设置为 fill=False对于条形图: import m
我正在尝试在 (6X3) 网格上创建子图。我对图例的位置有疑问。图例对所有子图都是通用的。 lgend 现在与 y 轴标签重叠 我尝试删除 constrained_layout=True 选项。但这在
我有一个带有一些线段( LineCollection )和一些点的图表。这些线和点有一些与它们相关的值,但没有绘制出来。我希望能够添加鼠标悬停工具提示或其他方法来轻松找到点和线的关联值。这对于点或线段
我想创建一个带有对齐不同曲线文本的图例的图。这是一个最小的工作示例: import matplotlib.pyplot as plt import numpy as np x=np.linspace(
可以说我正在用matplotlib绘制一条线并添加一个图例。 在图例中,其显示为------ Label。当绘制较小的图形尺寸以进行打印时,我发现该行的默认水平长度太长。 是否存在将------ La
我正在使用 matplotlib 构建一个 3D 散点图,但无法使生成的图形具有所有 3 个轴的共同原点。我怎样才能做到这一点? 我的代码(到目前为止),我还没有为轴规范实现任何定义,因为我对 Pyt
我有一个我想使用的绘图布局,其中 9 个不同的数据簇被布置在一个方形网格上。网格中的每个框都包含 3 个并排布置的箱线图。 我最初的想法是这将适合 3x3 子图布局,每个单独的子图本身被划分为 3x1
我的图形从y=-1变为y=10 我想在任意位置写一小段文字,例如x=2000,y=5: ax.annotate('MgII', xy=(2000.0, 5.0), xycoords='data')
我想使用LateX格式来构建一个表达式,其中出现一些数字,但这些数字是用LateX表达式中的变量表示的。 实际的目标是在axes.annotate()方法中使用它,但是为了讨论起见,这里是一个原理代码
我需要比较两组的二维分布。 当我使用 matplotlib.pyplot.contourf并覆盖图,每个等高线图的背景颜色填充整个图空间。有没有办法让每个等高线图的最低等高线级别透明,以便更容易看到每
在R中,有一个locator函数,类似于Matlab的ginput,您可以用鼠标单击图形并选择任何x,y坐标。此外,还有一个名为identify(x,y)的函数,如果您给它绘制了一组绘制的点x,y,然
我想用matplotlib生成矢量图。我尽力了-但输出是光栅图像。这是我使用的: import matplotlib matplotlib.use('Agg') import matplotlib.p
我正在尝试使用 matplotlib 制作具有非常小的灰点的散点图。由于点密度的原因,点需要很小。问题是 scatter() 函数的标记似乎既有线条又有填充。当标记很小时,只有线条可见,而看不到填充,
我不太明白为什么我无法在指定的限制内创建水平和垂直线。我想用这个框绑定(bind)数据。然而,双方似乎并没有遵守我的指示。为什么是这样? # CREATING A BOUNDING BOX # BOT
我是一名优秀的程序员,十分优秀!