使用不同样式绘制线而没有数据文件

问题描述 投票:0回答:1

以下代码创建了一个图。我的问题是:如何能使用不同的样式创建这两行而不将它们放入数据文件中并使用plot 'plotting_data.dat' index 0 with linespoints linestyle 1, '' index 1 with linespoints linestyle 2

set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5
set style line 2 \
    linecolor rgb '#dd181f' \
    linetype 1 linewidth 2 \
    pointtype 5 pointsize 1.5

# THIS WON'T WORK
# plot '-' index 0 with linespoints linestyle 1, \
#      '-' index 1 with linespoints linestyle 2

# THIS CREATES A PLOT
plot '-' with linespoints linestyle 1
# First data block (index 0)
# X   Y
  1   2
  2   3


# Second index block (index 1)
# X   Y
  3   2
  4   1

提前感谢。

gnuplot
1个回答
0
投票

您无需指定是否绝对需要通过'-'绘制数据。如果您想通过'-'使用数据绘制两个图,则必须提供两次数据。检查help data

还有另一种通过定义数据块将数据与gnuplot代码一起“传递”的方法。检查help datablocks

### data in code included
reset session

set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5
set style line 2 \
    linecolor rgb '#dd181f' \
    linetype 1 linewidth 2 \
    pointtype 5 pointsize 1.5

$Data <<EOD
# First data block (index 0)
# X   Y
  1   2
  2   3


# Second index block (index 1)
# X   Y
  3   2
  4   1
EOD

plot $Data index 0 with linespoints linestyle 1, \
     $Data index 1 with linespoints linestyle 2
### end of code
© www.soinside.com 2019 - 2024. All rights reserved.