0

I would like to plot a series of parametric plots, based on a user defined variable, say a. For example:

a=1 
plot a*sin(x) 
a=2 
replot a*sin(x)

However, it seems that when I update a, both plots are updated. Is it possible to keep the first plot as it is and plot the second one with a=2?

theozh
  • 22,244
  • 5
  • 28
  • 72
EmThorns
  • 119
  • 6

2 Answers2

0

I'm not sure whether I correctly understand your problem. Why do you want to replot? Why not looping the parameter a? Something like this:

Code:

### parametric plot
reset session
set colorsequence classic

set key top left
plot 0.25*x w l, \
     0.5*cos(x) w l, \
     for [a=1:3] a*sin(x) w l lw 2 ti sprintf("%g*sin(x)",a)

### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • Actually, I have to plot different data series, each of which is related to a set of different parameters. What I wrote is a very simple example. If I don't use replot, the previous plot gets deleted ... that's why I use replot. How can I keep the previous plots in my window? Thanks. – EmThorns Jan 28 '20 at 13:29
  • well, then your example was too minimal to make your problem clear. Another guess... see modified code. Also check https://stackoverflow.com/help/minimal-reproducible-example – theozh Jan 28 '20 at 18:48
0

When replotting, your command will be interpreted as a=2; plot a*sin(x), a*sin(x).

You could use another variable

b = 1
plot b*sin(x) 
a=2 
replot a*sin(x)

or put the variable assignment into the plot command

plot a=1, a*sin(x), a=2, a*sin(x)

enter image description here