我有这个非常简单的gnuplot代码:
splot x * x
这将绘制-10 我想从-10 换句话说,在图的一小部分中,表面应看起来像一条细带。其余应为空白空间。下面是使用我所拥有的图形来创建我想要的东西的辛苦工作。 我尝试操纵yrange
,但这同时改变了表面边界和轴边界。我也曾尝试禁用autoscale
,但不确定下一步该怎么做。
答案 0 :(得分:2)
一种方法是通过parametric
模式,该模式为您提供了一组单独的坐标(u
和v
)来设置范围
f(x,y) = x*x
set xrange [-10:10]
set yrange [-10:10]
set urange [-10:10]
set vrange [-10:-9]
set parametric
splot u, v, f(u,v)
或者,您可以通过使用++
特殊文件名而不是parametric
模式来达到相同的效果:
f(x,y) = x*x
set xrange [-10:10]
set yrange [-10:10]
set urange [-10:10]
set vrange [-10:-9]
splot "++" u 1:2:(f($1,$2)) w l
答案 1 :(得分:2)
在当前gnuplot(版本5.2.4)中,无论是否启用参数模式,都可以将采样范围与轴范围分开。请参见在线演示集中的示例: sampling.html (see plot #9)
答案 2 :(得分:1)
没有明确的parametric
在https://stackoverflow.com/a/51546029/895245中提到了此文档,并提供了文档链接,这是一个最小的示例:
set terminal png
set output 'splot-domain.png'
# Number of x and y samples.
set isosamples 10, 5
# Plotted domain.
set urange [-5.0 : 0.0]
set vrange [-5.0 : 5.0]
# Visible domain.
set xrange [-5.0 : 5.0]
set yrange [-5.0 : 5.0]
# Just to make plot look nicer.
set hidden3d
set xyplane at 0
set xlabel 'x'
set ylabel 'y'
splot '++' using 1:2:($2**2) with lines
输出:
在gnuplot 5.2补丁程序级别8上进行了测试。
答案 3 :(得分:0)
使用带有gnuplot的编程语言可能会更好地控制绘图。
这里是使用c和脚本的示例。
plot.c
#include <stdio.h>
#include <math.h>
int main()
{
int x, y;
double z;
for (y=-10; y <= 10; y++)
{
for (x=-10; x <= 10; x++)
{
z = x * 0.025;
printf("%f %f %f\n", (double)x, (double)y, 100 - cos(z * M_PI*2) * 100);
}
printf("\n");
}
fflush(stdout);
return 0;
}
plot.bat
gcc plot.c -o prog.exe -lm
prog > data.txt
echo splot "data.txt" using 1:2:3 with lines | gnuplot -p
plot.sh
gcc plot.c -o prog -lm
./prog > data.txt
echo 'splot "data.txt" using 1:2:3 with lines' | gnuplot -p
plot.py
import math
print("\"Surface One\"")
for y in range(-10, 10+1):
for x in range(-10, 10+1):
z = x * 0.025
print("%f %f %f 1" % (float(x), float(y), 100 - math.cos(z * math.pi*2) * 100))
print("")
print("")
print("\"Surface Two\"")
for y in range(-10, -8+1):
for x in range(-10, 10+1):
z = x * 0.025
print("%f %f %f 2" % (float(x), float(y), 100 - math.cos(z * math.pi*2) * 100))
print("")
print("")
print("\"Surface Three\"")
for y in range(-10, 10+1):
for x in range(-10, 10+1):
z = x * 0.1
print("%f %f %f 7" % (float(x)/2, float(y)/2, math.sin(z * math.pi*2) * 10))
print("")
print("")
plot.bat
cd %~dp0
python plot.py > data.txt
echo ^
set terminal wxt size 570,420; ^
stats "data.txt" u 1:2 nooutput; ^
set border 0x7F linecolor rgb "#555555"; ^
set grid xtics linecolor rgb "#888888" linewidth 0.2 linetype 9; ^
set grid ytics linecolor rgb "#888888" linewidth 0.2 linetype 9; ^
set grid ztics linecolor rgb "#888888" linewidth 0.2 linetype 9; ^
set xrange [-10.0:10.0]; ^
set yrange [-10.0:10.0]; ^
set zrange [-10.0:100.0]; ^
splot for [IDX=0:STATS_blocks-1] "data.txt" i IDX using 1:2:3:4 with lines ^
lc variable title columnheader(1) | gnuplot -p
plot.sh
#!/bin/bash
python plot.py > data.txt
echo \
'set terminal wxt size 570,420; \
stats "data.txt" u 1:2 nooutput; \
set border 0x7F linecolor rgb "#555555"; \
set grid xtics linecolor rgb "#888888" linewidth 0.2 linetype 9; \
set grid ytics linecolor rgb "#888888" linewidth 0.2 linetype 9; \
set grid ztics linecolor rgb "#888888" linewidth 0.2 linetype 9; \
set xrange [-10.0:10.0]; \
set yrange [-10.0:10.0]; \
set zrange [-10.0:100.0]; \
splot for [IDX=0:STATS_blocks-1] "data.txt" i IDX using 1:2:3:4 with lines \
lc variable title columnheader(1)' | gnuplot -p