Superimpose a line on a histogram in GnuplotHistogram using gnuplot?Read file line by line using ifstream in C++Why is reading lines from stdin much slower in C++ than Python?How to pass command line argument to gnuplot?add horizontal line histogram gnuplotGnuplot line typesGnuplot, superimpose curves with splotCurves superimposed to a surface in gnuplotGnuplot histogram with plot lineVariable sized bin widths with gnuplot histograms
I just entered the USA without passport control at Atlanta airport
How Hebrew Vowels Work
How much steel armor can you wear and still be able to swim?
Kelvin type connection
Scaling an object to change its key
How can the US president give an order to a civilian?
Definition of 'vrit'
Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?
How could I create a situation in which a PC has to make a saving throw or be forced to pet a dog?
Justifying Affordable Bespoke Spaceships
How can I improve my violin intonation for enharmonic notes?
One to Eleven Sum to Twenty Five
Why can't I craft scaffolding in Minecraft 1.14?
Are intrusions within a foreign embassy considered an act of war?
Is Newton's third law really correct?
How "fast" do astronomical events occur?
In the US, can a former president run again?
Do details of my undergraduate title matter?
What is this plant I saw for sale at a Romanian farmer's market?
Movie: during a weekend in a house, a young kid befriends someone eating anything, they find the place of a plant scientist who reached immortality
How did Frodo know where the Bree village was?
What is the highest power supply a Raspberry pi 3 B can handle without getting damaged?
Are there examples of rowers who also fought?
Why do you need to heat the pan before heating the olive oil?
Superimpose a line on a histogram in Gnuplot
Histogram using gnuplot?Read file line by line using ifstream in C++Why is reading lines from stdin much slower in C++ than Python?How to pass command line argument to gnuplot?add horizontal line histogram gnuplotGnuplot line typesGnuplot, superimpose curves with splotCurves superimposed to a surface in gnuplotGnuplot histogram with plot lineVariable sized bin widths with gnuplot histograms
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I use C++ in Xcode on Mac and a pipe method to communicate with Gnuplot. I am interested in converting my arrays into graphs directly through the program, after I run it. Using
FILE *f = popen("gnuplot -persist", "w");
I open the file and then communicate using fprintf.
Now, I have some data in arrays of interest. w is a "proposed" array of standard normal variables and I intend to check if it is indeed a Gaussian distribution with mean = 0 and variance = 1 .To do that I plot a histogram. After that I want to superimpose a real Gaussian function, which has ex as a x coordinate values and gauss as y coordinate values directly on the histogram. How can I do that?
Here's the code so far:
double start = -4; //min
double end = 4 ; //max
double numberofbins = 100;
double width = (end-start)/numberofbins ;
fprintf (f,
"set ylabel '# of elements'n"
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"f(x)= e**((-x**2)/2) / sqrt(2*pi)n"
"plot '-' using (bin($1)):(1) smooth freq with boxes,'' u $2:$3 with lines linestyle 1n",start,end,numberofbins)
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %g %gn", w[i], ex[i], gauss[i]);
fclose(f);
Here is the result if I run the demonstrated code:

As we can see, the binning was successful but the line was omitted and gives the following error:
gnuplot> plot '-' using (bin($1)):(1) smooth freq with boxes,'' u $2:$3 with lines linestyle 1
^
line 100000: column() called from invalid context
I have checked online but nobody is practicing communicating with Gnuplot that way.
If I plot only the 2:3 part (without binning), I get this graph:

Thus, the problem might be with the compatibility of these two plots.
c++ gnuplot
add a comment |
I use C++ in Xcode on Mac and a pipe method to communicate with Gnuplot. I am interested in converting my arrays into graphs directly through the program, after I run it. Using
FILE *f = popen("gnuplot -persist", "w");
I open the file and then communicate using fprintf.
Now, I have some data in arrays of interest. w is a "proposed" array of standard normal variables and I intend to check if it is indeed a Gaussian distribution with mean = 0 and variance = 1 .To do that I plot a histogram. After that I want to superimpose a real Gaussian function, which has ex as a x coordinate values and gauss as y coordinate values directly on the histogram. How can I do that?
Here's the code so far:
double start = -4; //min
double end = 4 ; //max
double numberofbins = 100;
double width = (end-start)/numberofbins ;
fprintf (f,
"set ylabel '# of elements'n"
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"f(x)= e**((-x**2)/2) / sqrt(2*pi)n"
"plot '-' using (bin($1)):(1) smooth freq with boxes,'' u $2:$3 with lines linestyle 1n",start,end,numberofbins)
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %g %gn", w[i], ex[i], gauss[i]);
fclose(f);
Here is the result if I run the demonstrated code:

As we can see, the binning was successful but the line was omitted and gives the following error:
gnuplot> plot '-' using (bin($1)):(1) smooth freq with boxes,'' u $2:$3 with lines linestyle 1
^
line 100000: column() called from invalid context
I have checked online but nobody is practicing communicating with Gnuplot that way.
If I plot only the 2:3 part (without binning), I get this graph:

Thus, the problem might be with the compatibility of these two plots.
c++ gnuplot
either use...'' u 2:3 with lines...or...'' u ($2):($3) with lines...
– theozh
Mar 25 at 6:38
@theozh Now it gives this error:line 100000: warning: Skipping data file with no valid points
– Ruffi
Mar 25 at 6:59
1
usingplot '-' using ...the data has to directly follow the plot command and to be finished withe. I don't think this is the case with your data.
– theozh
Mar 25 at 7:08
@theozh I do not understand your last comment, could you please elaborate more on this?
– Ruffi
Mar 25 at 7:15
add a comment |
I use C++ in Xcode on Mac and a pipe method to communicate with Gnuplot. I am interested in converting my arrays into graphs directly through the program, after I run it. Using
FILE *f = popen("gnuplot -persist", "w");
I open the file and then communicate using fprintf.
Now, I have some data in arrays of interest. w is a "proposed" array of standard normal variables and I intend to check if it is indeed a Gaussian distribution with mean = 0 and variance = 1 .To do that I plot a histogram. After that I want to superimpose a real Gaussian function, which has ex as a x coordinate values and gauss as y coordinate values directly on the histogram. How can I do that?
Here's the code so far:
double start = -4; //min
double end = 4 ; //max
double numberofbins = 100;
double width = (end-start)/numberofbins ;
fprintf (f,
"set ylabel '# of elements'n"
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"f(x)= e**((-x**2)/2) / sqrt(2*pi)n"
"plot '-' using (bin($1)):(1) smooth freq with boxes,'' u $2:$3 with lines linestyle 1n",start,end,numberofbins)
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %g %gn", w[i], ex[i], gauss[i]);
fclose(f);
Here is the result if I run the demonstrated code:

As we can see, the binning was successful but the line was omitted and gives the following error:
gnuplot> plot '-' using (bin($1)):(1) smooth freq with boxes,'' u $2:$3 with lines linestyle 1
^
line 100000: column() called from invalid context
I have checked online but nobody is practicing communicating with Gnuplot that way.
If I plot only the 2:3 part (without binning), I get this graph:

Thus, the problem might be with the compatibility of these two plots.
c++ gnuplot
I use C++ in Xcode on Mac and a pipe method to communicate with Gnuplot. I am interested in converting my arrays into graphs directly through the program, after I run it. Using
FILE *f = popen("gnuplot -persist", "w");
I open the file and then communicate using fprintf.
Now, I have some data in arrays of interest. w is a "proposed" array of standard normal variables and I intend to check if it is indeed a Gaussian distribution with mean = 0 and variance = 1 .To do that I plot a histogram. After that I want to superimpose a real Gaussian function, which has ex as a x coordinate values and gauss as y coordinate values directly on the histogram. How can I do that?
Here's the code so far:
double start = -4; //min
double end = 4 ; //max
double numberofbins = 100;
double width = (end-start)/numberofbins ;
fprintf (f,
"set ylabel '# of elements'n"
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"f(x)= e**((-x**2)/2) / sqrt(2*pi)n"
"plot '-' using (bin($1)):(1) smooth freq with boxes,'' u $2:$3 with lines linestyle 1n",start,end,numberofbins)
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %g %gn", w[i], ex[i], gauss[i]);
fclose(f);
Here is the result if I run the demonstrated code:

As we can see, the binning was successful but the line was omitted and gives the following error:
gnuplot> plot '-' using (bin($1)):(1) smooth freq with boxes,'' u $2:$3 with lines linestyle 1
^
line 100000: column() called from invalid context
I have checked online but nobody is practicing communicating with Gnuplot that way.
If I plot only the 2:3 part (without binning), I get this graph:

Thus, the problem might be with the compatibility of these two plots.
c++ gnuplot
c++ gnuplot
edited Mar 25 at 19:44
Vinicius Placco
1,2722720
1,2722720
asked Mar 25 at 5:57
RuffiRuffi
113
113
either use...'' u 2:3 with lines...or...'' u ($2):($3) with lines...
– theozh
Mar 25 at 6:38
@theozh Now it gives this error:line 100000: warning: Skipping data file with no valid points
– Ruffi
Mar 25 at 6:59
1
usingplot '-' using ...the data has to directly follow the plot command and to be finished withe. I don't think this is the case with your data.
– theozh
Mar 25 at 7:08
@theozh I do not understand your last comment, could you please elaborate more on this?
– Ruffi
Mar 25 at 7:15
add a comment |
either use...'' u 2:3 with lines...or...'' u ($2):($3) with lines...
– theozh
Mar 25 at 6:38
@theozh Now it gives this error:line 100000: warning: Skipping data file with no valid points
– Ruffi
Mar 25 at 6:59
1
usingplot '-' using ...the data has to directly follow the plot command and to be finished withe. I don't think this is the case with your data.
– theozh
Mar 25 at 7:08
@theozh I do not understand your last comment, could you please elaborate more on this?
– Ruffi
Mar 25 at 7:15
either use
...'' u 2:3 with lines... or ...'' u ($2):($3) with lines...– theozh
Mar 25 at 6:38
either use
...'' u 2:3 with lines... or ...'' u ($2):($3) with lines...– theozh
Mar 25 at 6:38
@theozh Now it gives this error:
line 100000: warning: Skipping data file with no valid points– Ruffi
Mar 25 at 6:59
@theozh Now it gives this error:
line 100000: warning: Skipping data file with no valid points– Ruffi
Mar 25 at 6:59
1
1
using
plot '-' using ... the data has to directly follow the plot command and to be finished with e. I don't think this is the case with your data.– theozh
Mar 25 at 7:08
using
plot '-' using ... the data has to directly follow the plot command and to be finished with e. I don't think this is the case with your data.– theozh
Mar 25 at 7:08
@theozh I do not understand your last comment, could you please elaborate more on this?
– Ruffi
Mar 25 at 7:15
@theozh I do not understand your last comment, could you please elaborate more on this?
– Ruffi
Mar 25 at 7:15
add a comment |
2 Answers
2
active
oldest
votes
there are different ways to plot "inline" data
plot '-' u 1:2 w lines
1 11
2 22
3 33
e
From gnuplot help special-filenames
If you use both '-' and '' on the same plot command, you'll need to
have two sets of inline data, ...
This means:
plot '-' u 1:2 w boxes, '' u 1:2 w lines
1 11
2 22
3 33
e
1 11
2 22
3 33
e
So, instead, I would generate a datablock in the beginning of your generated command string and reuse the data as many times as you need it during your plotting command.
$Data <<EOD
1 11
2 22
3 33
EOD
plot $Data u 1:2 w boxes, '' u 1:2 w lines
Sorry for the late reply, but this is not the case. I need to superpose a theoretical Gaussian line on the histogram. As you see, the histogram's height is 4000 and the line's height is 0.4.
– Ruffi
Mar 30 at 21:24
then normalize both to 1 or scale the one or the other. For example:plot $Data u 1:2 w boxes, '' u 1:($3/0.4*4000) w linesor something like that.
– theozh
Mar 30 at 22:32
I have solved the problem by creating a second axis and plotting it according to it. Thanks for the help, I really did not know about the "e" business!
– Ruffi
Mar 31 at 15:00
add a comment |
I have solved the problem by creating a second y axis on the same graph and plotting according to it. The code used was:
fprintf (f,
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"set ytics 100 nomirror tc lt 1n"
"set ylabel '# of elements' tc lt 1n"
"set y2tics 0.4 nomirror tc lt 2n"
"set y2label 'Theoretical Gaussian' tc lt 2n"
"plot '-' using (bin($1)):(1) smooth freq with boxes title 'Generator Histogram','-' u 1:2 with l axes x1y2 title 'Theoretical Gaussian (mean=0, std = 1)'n",start,end,numberofbins) ;
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%gn", w[i]);
fprintf(f,"en");
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %gn",ex[i], gauss[i]);
fprintf(f,"en");
fclose(f);
which plots this:
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331962%2fsuperimpose-a-line-on-a-histogram-in-gnuplot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
there are different ways to plot "inline" data
plot '-' u 1:2 w lines
1 11
2 22
3 33
e
From gnuplot help special-filenames
If you use both '-' and '' on the same plot command, you'll need to
have two sets of inline data, ...
This means:
plot '-' u 1:2 w boxes, '' u 1:2 w lines
1 11
2 22
3 33
e
1 11
2 22
3 33
e
So, instead, I would generate a datablock in the beginning of your generated command string and reuse the data as many times as you need it during your plotting command.
$Data <<EOD
1 11
2 22
3 33
EOD
plot $Data u 1:2 w boxes, '' u 1:2 w lines
Sorry for the late reply, but this is not the case. I need to superpose a theoretical Gaussian line on the histogram. As you see, the histogram's height is 4000 and the line's height is 0.4.
– Ruffi
Mar 30 at 21:24
then normalize both to 1 or scale the one or the other. For example:plot $Data u 1:2 w boxes, '' u 1:($3/0.4*4000) w linesor something like that.
– theozh
Mar 30 at 22:32
I have solved the problem by creating a second axis and plotting it according to it. Thanks for the help, I really did not know about the "e" business!
– Ruffi
Mar 31 at 15:00
add a comment |
there are different ways to plot "inline" data
plot '-' u 1:2 w lines
1 11
2 22
3 33
e
From gnuplot help special-filenames
If you use both '-' and '' on the same plot command, you'll need to
have two sets of inline data, ...
This means:
plot '-' u 1:2 w boxes, '' u 1:2 w lines
1 11
2 22
3 33
e
1 11
2 22
3 33
e
So, instead, I would generate a datablock in the beginning of your generated command string and reuse the data as many times as you need it during your plotting command.
$Data <<EOD
1 11
2 22
3 33
EOD
plot $Data u 1:2 w boxes, '' u 1:2 w lines
Sorry for the late reply, but this is not the case. I need to superpose a theoretical Gaussian line on the histogram. As you see, the histogram's height is 4000 and the line's height is 0.4.
– Ruffi
Mar 30 at 21:24
then normalize both to 1 or scale the one or the other. For example:plot $Data u 1:2 w boxes, '' u 1:($3/0.4*4000) w linesor something like that.
– theozh
Mar 30 at 22:32
I have solved the problem by creating a second axis and plotting it according to it. Thanks for the help, I really did not know about the "e" business!
– Ruffi
Mar 31 at 15:00
add a comment |
there are different ways to plot "inline" data
plot '-' u 1:2 w lines
1 11
2 22
3 33
e
From gnuplot help special-filenames
If you use both '-' and '' on the same plot command, you'll need to
have two sets of inline data, ...
This means:
plot '-' u 1:2 w boxes, '' u 1:2 w lines
1 11
2 22
3 33
e
1 11
2 22
3 33
e
So, instead, I would generate a datablock in the beginning of your generated command string and reuse the data as many times as you need it during your plotting command.
$Data <<EOD
1 11
2 22
3 33
EOD
plot $Data u 1:2 w boxes, '' u 1:2 w lines
there are different ways to plot "inline" data
plot '-' u 1:2 w lines
1 11
2 22
3 33
e
From gnuplot help special-filenames
If you use both '-' and '' on the same plot command, you'll need to
have two sets of inline data, ...
This means:
plot '-' u 1:2 w boxes, '' u 1:2 w lines
1 11
2 22
3 33
e
1 11
2 22
3 33
e
So, instead, I would generate a datablock in the beginning of your generated command string and reuse the data as many times as you need it during your plotting command.
$Data <<EOD
1 11
2 22
3 33
EOD
plot $Data u 1:2 w boxes, '' u 1:2 w lines
edited Apr 1 at 6:23
answered Mar 25 at 7:27
theozhtheozh
2,484414
2,484414
Sorry for the late reply, but this is not the case. I need to superpose a theoretical Gaussian line on the histogram. As you see, the histogram's height is 4000 and the line's height is 0.4.
– Ruffi
Mar 30 at 21:24
then normalize both to 1 or scale the one or the other. For example:plot $Data u 1:2 w boxes, '' u 1:($3/0.4*4000) w linesor something like that.
– theozh
Mar 30 at 22:32
I have solved the problem by creating a second axis and plotting it according to it. Thanks for the help, I really did not know about the "e" business!
– Ruffi
Mar 31 at 15:00
add a comment |
Sorry for the late reply, but this is not the case. I need to superpose a theoretical Gaussian line on the histogram. As you see, the histogram's height is 4000 and the line's height is 0.4.
– Ruffi
Mar 30 at 21:24
then normalize both to 1 or scale the one or the other. For example:plot $Data u 1:2 w boxes, '' u 1:($3/0.4*4000) w linesor something like that.
– theozh
Mar 30 at 22:32
I have solved the problem by creating a second axis and plotting it according to it. Thanks for the help, I really did not know about the "e" business!
– Ruffi
Mar 31 at 15:00
Sorry for the late reply, but this is not the case. I need to superpose a theoretical Gaussian line on the histogram. As you see, the histogram's height is 4000 and the line's height is 0.4.
– Ruffi
Mar 30 at 21:24
Sorry for the late reply, but this is not the case. I need to superpose a theoretical Gaussian line on the histogram. As you see, the histogram's height is 4000 and the line's height is 0.4.
– Ruffi
Mar 30 at 21:24
then normalize both to 1 or scale the one or the other. For example:
plot $Data u 1:2 w boxes, '' u 1:($3/0.4*4000) w lines or something like that.– theozh
Mar 30 at 22:32
then normalize both to 1 or scale the one or the other. For example:
plot $Data u 1:2 w boxes, '' u 1:($3/0.4*4000) w lines or something like that.– theozh
Mar 30 at 22:32
I have solved the problem by creating a second axis and plotting it according to it. Thanks for the help, I really did not know about the "e" business!
– Ruffi
Mar 31 at 15:00
I have solved the problem by creating a second axis and plotting it according to it. Thanks for the help, I really did not know about the "e" business!
– Ruffi
Mar 31 at 15:00
add a comment |
I have solved the problem by creating a second y axis on the same graph and plotting according to it. The code used was:
fprintf (f,
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"set ytics 100 nomirror tc lt 1n"
"set ylabel '# of elements' tc lt 1n"
"set y2tics 0.4 nomirror tc lt 2n"
"set y2label 'Theoretical Gaussian' tc lt 2n"
"plot '-' using (bin($1)):(1) smooth freq with boxes title 'Generator Histogram','-' u 1:2 with l axes x1y2 title 'Theoretical Gaussian (mean=0, std = 1)'n",start,end,numberofbins) ;
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%gn", w[i]);
fprintf(f,"en");
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %gn",ex[i], gauss[i]);
fprintf(f,"en");
fclose(f);
which plots this:
add a comment |
I have solved the problem by creating a second y axis on the same graph and plotting according to it. The code used was:
fprintf (f,
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"set ytics 100 nomirror tc lt 1n"
"set ylabel '# of elements' tc lt 1n"
"set y2tics 0.4 nomirror tc lt 2n"
"set y2label 'Theoretical Gaussian' tc lt 2n"
"plot '-' using (bin($1)):(1) smooth freq with boxes title 'Generator Histogram','-' u 1:2 with l axes x1y2 title 'Theoretical Gaussian (mean=0, std = 1)'n",start,end,numberofbins) ;
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%gn", w[i]);
fprintf(f,"en");
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %gn",ex[i], gauss[i]);
fprintf(f,"en");
fclose(f);
which plots this:
add a comment |
I have solved the problem by creating a second y axis on the same graph and plotting according to it. The code used was:
fprintf (f,
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"set ytics 100 nomirror tc lt 1n"
"set ylabel '# of elements' tc lt 1n"
"set y2tics 0.4 nomirror tc lt 2n"
"set y2label 'Theoretical Gaussian' tc lt 2n"
"plot '-' using (bin($1)):(1) smooth freq with boxes title 'Generator Histogram','-' u 1:2 with l axes x1y2 title 'Theoretical Gaussian (mean=0, std = 1)'n",start,end,numberofbins) ;
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%gn", w[i]);
fprintf(f,"en");
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %gn",ex[i], gauss[i]);
fprintf(f,"en");
fclose(f);
which plots this:
I have solved the problem by creating a second y axis on the same graph and plotting according to it. The code used was:
fprintf (f,
"set xlabel 'The numbers'n"
"Min = %gn" //where binning starts
"Max = %gn" // where binning ends
"n = %gn" // the number of bins
"width = 10**(-1)n" // binwidth; (Max-Min)/n
"bin(x) = width*(floor((x-Min)/width)+0.5) + Minn"
"set ytics 100 nomirror tc lt 1n"
"set ylabel '# of elements' tc lt 1n"
"set y2tics 0.4 nomirror tc lt 2n"
"set y2label 'Theoretical Gaussian' tc lt 2n"
"plot '-' using (bin($1)):(1) smooth freq with boxes title 'Generator Histogram','-' u 1:2 with l axes x1y2 title 'Theoretical Gaussian (mean=0, std = 1)'n",start,end,numberofbins) ;
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%gn", w[i]);
fprintf(f,"en");
for (int i= 0; i < numberofpoints; i++)
fprintf(f, "%g %gn",ex[i], gauss[i]);
fprintf(f,"en");
fclose(f);
which plots this:
answered Mar 31 at 15:59
RuffiRuffi
113
113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331962%2fsuperimpose-a-line-on-a-histogram-in-gnuplot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
either use
...'' u 2:3 with lines...or...'' u ($2):($3) with lines...– theozh
Mar 25 at 6:38
@theozh Now it gives this error:
line 100000: warning: Skipping data file with no valid points– Ruffi
Mar 25 at 6:59
1
using
plot '-' using ...the data has to directly follow the plot command and to be finished withe. I don't think this is the case with your data.– theozh
Mar 25 at 7:08
@theozh I do not understand your last comment, could you please elaborate more on this?
– Ruffi
Mar 25 at 7:15