Prior to this one must manually create and set separate y-axis. With histcounts you can get the bar heights and rescale them however you want, but you must plot the bars yourself.Īs you cannot rescale the histogram heights, you must plot them on separate axis.įrom release 2016a and onwards, you can use yyaxis left for the scatter plot and yyaxis right for the histogram, see Matlab documentation: To restate the problem, the histogram function allows you to control many graphics properties like transparency, but only gives you a limited number of options to change the height of the bars. Which gives You cannot set the read-only property 'Values' of Histogram.Īlternatively one can get the bin counts using histcounts, but as far as I can tell, the bar function does not allow one to set the face alpha or have other configurability as per the call to histogram.Īs discussed in the comments there are several solutions that depend on the version of Matlab you are using. Now, one might naively try to rescale the histogram using: h.Values = h.Values/max(h.Values) * maxlim Where the line chart is completely obscured by the histogram. Maxlim = max(ax.XLim) % store maximum y-value to rescale histogram to this value % plot line, histogram, then histogram and line. I am having trouble plotting a histogram of the x-values of my data points together with a line showing the relationship between x and y, mainly because the scale in the y direction of the histogram is not of the same magnitude as the scale in the line plot.