我想在 gnuplot 的文本文件中绘制一个具有给定 4 个坐标的矩形。矩形可能与 x 轴成一定角度
I want to plot a rectangle with given 4 coordinates in a text file in gnuplot. The rectangle may be at an angle to x axis
如何从文件中读取数据并绘制矩形?
给定的文本文件具有以下格式,最多 50 行:
x1 y1 x2 y2 x3 y3 x4 y4
其中 (x1,y1)、(x2,y2)、(x3,y3) 和 (x4,y4) 是矩形的四个顶点。矩形具有随机方向。我如何在 gnuplot 中绘制一系列矩形?
如果有人能告诉我如何在使用 set object polygon 时读取文件,那可能也会有帮助
我想要的:设置对象多边形从到到到 .
或者,gnuplot 中还有其他更简单的代码吗?或者有 python 解决方案吗?
这是我们讨论过的 Python 代码。
您输入的文件格式为:
__ __ x1 y1 x2 y2 x3 y3 x4 y4
代码。
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('car.txt')
data = [i[2:] for i in data]
for d in data:
Xs = d[::2]
Ys = d[1::2]
for i in range(4):
if i < 3:
plt.plot([Xs[i],Xs[i+1]],[Ys[i],Ys[i+1]],'k-',lw=2)
elif i == 3:
plt.plot([Xs[i],Xs[0]],[Ys[i],Ys[0]],'k-',lw=2)
plt.show()
我的 Gnuplot
解决方案(不仅适用于矩形,还适用于任何类型的多边形):
plot 'rectal.dat' u 1:2:(-):(-) with vectors nohead lc 1 title 'Rectangle', \
'' u 3:4:(-):(-) with vectors nohead lc 1 notitle, \
'' u 5:6:(-):(-) with vectors nohead lc 1 notitle, \
'' u 7:8:(-):(-) with vectors nohead lc 1 notitle
来自
0 0 0 1 1 1 1 0
0 0 0 2 2 2 2 0
-0.5 -0.5 -1 1 -0.5 2 0 1
如何从文件中读取数据并绘制矩形? 给定的文本文件具有以下格式,最多 50 行: x1 y1 x2 y2 x3 y3 x4 y4
其中 (x1,y1)、(x2,y2)、(x3,y3) 和 (x4,y4) 是矩形的四个顶点。矩形具有随机方向。我如何在 gnuplot 中绘制一系列矩形?
如果有人能告诉我如何在使用 set object polygon 时读取文件,那可能也会有帮助 我想要的:设置对象多边形从到到到 .
或者,gnuplot 中还有其他更简单的代码吗?或者有 python 解决方案吗?
这是我们讨论过的 Python 代码。
您输入的文件格式为:
__ __ x1 y1 x2 y2 x3 y3 x4 y4
代码。
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('car.txt')
data = [i[2:] for i in data]
for d in data:
Xs = d[::2]
Ys = d[1::2]
for i in range(4):
if i < 3:
plt.plot([Xs[i],Xs[i+1]],[Ys[i],Ys[i+1]],'k-',lw=2)
elif i == 3:
plt.plot([Xs[i],Xs[0]],[Ys[i],Ys[0]],'k-',lw=2)
plt.show()
我的 Gnuplot
解决方案(不仅适用于矩形,还适用于任何类型的多边形):
plot 'rectal.dat' u 1:2:(-):(-) with vectors nohead lc 1 title 'Rectangle', \
'' u 3:4:(-):(-) with vectors nohead lc 1 notitle, \
'' u 5:6:(-):(-) with vectors nohead lc 1 notitle, \
'' u 7:8:(-):(-) with vectors nohead lc 1 notitle
0 0 0 1 1 1 1 0
0 0 0 2 2 2 2 0
-0.5 -0.5 -1 1 -0.5 2 0 1