# Thread Subject: how to draw histogram and line graph in same plot?

 Subject: how to draw histogram and line graph in same plot? From: BP Date: 22 Jun, 2012 09:47:07 Message: 1 of 2 I did the below to draw a histogram which reflects probability of a dataset (400x1), and use ksdensity to find out the probability distribution. X-axis has a range between -4 to 8. However, for histogram Y-axis has a value 0-180, whereas ksdensity Y-axis has a value 0-0.5. How can draw a graph with histogram and line graph in the same plot? I tried to use plotyy, however it doesn't seems to support the designated x-axis as I have to set the vector lengths of x = y = 400. %% read from file     fid = fopen('t1_error.txt','r');     C = textscan(fid, '%.3f'); % return 400x1 array     fclose(fid); %% histogram     x_step = -1:0.1:7;     hist(C{1}, x_step);     xlabel('Relative Error');     ylabel('Probability');          %% ksdensity (distribution)     hold on     [f, xi] = ksdensity(C{1});     plot(xi, f);     hold off
 Subject: how to draw histogram and line graph in same plot? From: dpb Date: 22 Jun, 2012 18:06:18 Message: 2 of 2 On 6/22/2012 4:47 AM, BP wrote: > I did the below to draw a histogram which reflects probability of a > dataset (400x1), and use ksdensity to find out the probability > distribution. X-axis has a range between -4 to 8. However, for histogram > Y-axis has a value 0-180, whereas ksdensity Y-axis has a value 0-0.5. > How can draw a graph with histogram and line graph in the same plot? I > tried to use plotyy, however it doesn't seems to support the designated > x-axis as I have to set the vector lengths of x = y = 400. ... Did you try the two-handle version of plotyy, I guess? It didn't work here w/ a trial but I have a very old release; it might have gotten more flexibility since. plotyy(X1,Y1,X2,Y2,'function1','function2') It does use overlapping x-axes, though so unless it's gotten very clever problem has same problem (or it's what you already tried w/ it) I think you'll need to draw the second axis manually--there's example of multiple axes plots at --

### Everyone's Tags:

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.