ddm_ingram
ddm_ingram

Reputation: 111

Matlab scatterhist plots - display only one histogram

In Matlab, I want to plot data as a scatter plot, and display the marginal histogram at the side of one axis only.

I came across the scatterhist() function, which does exactly what I was looking for, except it always displays marginal histograms for both X and Y axes. Surely there's a way to remove one, but can't find the options.

My code as an example:

h = scatterhist(xrange, ydata, ...
    'Kernel','on', 'Location', 'SouthEast', ...
    'Direction','out', 'Marker','.');

An image of my problem is below (I am using the kernel density line instead of the actual histogram):

enter image description here

Note: I am able to open the property editor for the figure and manually remove a histogram by clicking and deleting, and furthermore access the source code for that modified figure, but this doesn't seem to provide me with a solution.

Thank you!

Upvotes: 5

Views: 1961

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112699

The function scatterhist creates three axes. Calling it as h = scatterhist(...) gives a 1×3 vector h with handles to those axes. You only need to delete the second:

h = scatterhist(...);
delete(h(2))

Upvotes: 5

Related Questions