Reputation: 2202
I'm creating a density histogram using bar(). The Y-vector holds my sample data, and I create the bar graph using the following code:
[nelements, centers] = hist(Y,(-9.5:1:7.5));
bar(centers,nelements/numSamples,'hist')
axis([-10 8 0 .33])
How would I go about placing a green 'X' along the x-axis of the bar chart if that value exists in Y? (Even better would be if a dot-plot could be created along the x-axis instead, so duplicate values aren't blocking each other).
Upvotes: 0
Views: 284
Reputation: 8476
If by "that value exists in Y" you mean that the respective histogram count for that bin is larger than zero, then this should work:
ind = find(nelements > 0);
hold all
plot(centers(ind), 0, 'xg')
If by "dot-plot" you mean a one-dimensional scatter plot, this does it:
hold all
plot(Y, 0, 'xg')
In both cases the green 'X's are located on the x-axis, but it might look better if you put them slightly below. In the latter case e.g.:
yl = ylim;
yl(1) = -0.1 * diff(yl);
hold all
plot(Y, -0.05 * diff(yl), 'xg')
ylim(yl)
Upvotes: 1