Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

graph - Gnuplot: can I make x axis stretch at some data points?

enter image description hereI have vector of time points which will be represented at x axis.
some of these time points occur at certain sign and other time points occur at different sign.
I want to scale x to y for first sign as x=1:y=1 .
I want to scale x to y for second sign as x=2:y=1
So that I will have one graph with x axis stretched at some points" x unit = double space e.g. 2 cm for 1 hour" and contracted at other points "x unit= single space e.g. 1 cm for 1 hour"
I have array with same index as time array which has 1 for single space time points and 2 for double space time points.
can I plot this in gnuplot? UPDATE:
if it is not possible in gnuplot ,is there any other library which can draw points with control of axis scale per point?"one array for axis scale per point and another for axis data??"
UPDATE:
data points:100 50 70 130 40 20 30 50 88 93
points width:1 1 1 2 2 2 2 1 1 1
time ticks : 1 2 3 4 5 6 7 8 9 10
these time ticks should be on x axis but with space between 1 2 3 as 1 unit e.g. 1 cm and space between 4 5 6 7 as 2 units e.g. 2 cm then between 8 9 10 as 1 unit
the data points will be 1000000 with random 1 and 2 units portions.
I do not know how to draw their graph.

question from:https://stackoverflow.com/questions/65855116/gnuplot-can-i-make-x-axis-stretch-at-some-data-points

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm still not sure whether I fully understand, but here is what I think you might want. So, you have events which are just counted from 1, ... N. These events do not occur in regular timesteps. Sometimes after 1 second, some times after 2 seconds. In order to plot this you simply have to sum up all these time differences, e.g. in a variable t.

Code:

### add variable stepsize for x-values
reset session

$Data <<EOD
 1   1  100 
 2   1   50
 3   1   70
 4   2  130
 5   2   40
 6   2   20
 7   2   30
 8   1   50
 9   1   88
10   1   93
EOD

set grid x

plot t=0 $Data u (t):(t=t+$2,$3) w lp pt 7 notitle
### end of code

Result:

enter image description here

Addition:

Here is another attempt trying to understand what you mean. That's what I understand now from your question and comments. You have events and the distance between them are as follows: Distance between 1,2,3 should be 1, between 3,4,5,6,7 should be 2, between 7,8,9,10 should be 1.

# event    1   2   3   4   5   6   7   8   9   10
# distance   1   1   2   2   2   2   1   1   1

Code: (you can skip the second line of the plot command. It's just to show event number)

### add variable stepsize for x-values
reset session

$Data <<EOD 
 1   1  100
 2   1   50
 3   1   70
 4   2  130
 5   2   40
 6   2   20
 7   2   30
 8   1   50
 9   1   88
10   1   93
EOD

set grid x
set offsets 0,1,0,0

plot t=0 $Data u (t=t+$2):3 w lp pt 7 notitle, 
     t=0 ''    u (t=t+$2):3:1 w labels offset 0,1 notitle
### end of code

Result:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...