0

I am using Monte Carlo Simulation to calculate the probability of failure and I want to paint the points which represents the failure (in red) in the scatter histogram. I can I do it? The code is below

% Histograms

hist(S,20)

hold on

hist(R,40)

set(findobj('Type','patch'),'Facecolor','none','Edgecolor','black')

set(gca,'Fontsize',18,'Fontname','euclid')

xlabel('R & S')


figure

scatterhist(R,S)

xlabel('R'),ylabel('S')
user3641311
  • 175
  • 2
  • 11
  • How is "failure" defined? Is it given by `I` equal to 1? – Luis Mendo Oct 14 '14 at 10:21
  • Failure is defined by variable I, which represents the cases where R is smaller than S. Hope I could help – user3641311 Oct 14 '14 at 10:25
  • Z is a vector that saves all the probability of failure (pf). Then all cases of pf which is smaller than 1, that represents the failure (I<0) it counts to pf. In the scatter graph I would like to paint these points with red colour. – user3641311 Oct 14 '14 at 10:28

1 Answers1

2

Replace your line

scatterhist(R,S)

by the following:

h_axes = scatterhist(R, S); %// get handles to the three axes 
h_values = get(h_axes(1), 'children'); %// get handle to plotted data
set(h_values, 'XData', R(~I), 'YData', S(~I)); %// remove failures
axes(h_axes(1))
hold on
plot(R(I), S(I), 'ro'); %// put failures back, in red

enter image description here

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • Can you put the failure point in the front of the graph? Instead of in the back? Thanks – user3641311 Oct 14 '14 at 10:36
  • Or rotate both graph's (FDP) so the base of them face the axis? Thanks a lot – user3641311 Oct 14 '14 at 10:42
  • 1
    For the first question: The failure points are already on top. If you to make it stand out more, replace my last line by `plot(R(I), S(I), 'r.', 'markersize', 20)` – Luis Mendo Oct 14 '14 at 10:50
  • 1
    Just change the `'YDir'` or `'XDir'` property of their axes to `'reverse'`: that is, `set(h_axes(2), 'YDir', 'Reverse'), set(h_axes(3), 'XDir', 'Reverse')` – Luis Mendo Oct 14 '14 at 11:45
  • Only one thing: the left histogram didnt rotate. `figure set(gcf,'color','w'); h_axes = scatterhist(R, S); %// get handles to the three axes h_values = get(h_axes(1), 'children'); %// get handle to plotted data set(h_values, 'XData', R(~I), 'YData', S(~I)); %// remove failures axes(h_axes(1)) set(h_axes(2), 'YDir', 'Reverse') set(h_axes(3), 'XDir', 'Reverse') hold on plot(R(I), S(I), 'r.', 'markersize', 20); %// put failures back, in red xlabel('R'),ylabel('S')` This is the code I have. Thanks again and sorry to bother! – user3641311 Oct 14 '14 at 20:58
  • 1
    Well, it does for me. The line responsible for that is `set(h_axes(3), 'XDir', 'Reverse')` – Luis Mendo Oct 14 '14 at 21:02
  • I dont know then. The left graph doesnt rotate. I mean, it's base should be facing the yy axis instead of its peak. I dont know if I am explaining myself in the proper way. – user3641311 Oct 14 '14 at 21:07
  • 1
    Yes, I get what you mean. It should work. Try this code alone: `h_axes = scatterhist(R, S); set(h_axes(3), 'XDir', 'Reverse')`. Does it work? – Luis Mendo Oct 14 '14 at 21:08
  • something like this: `figure set(gcf,'color','w'); h_axes = scatterhist(R, S); %// get handles to the three axes h_values = get(h_axes(1), 'children'); %// get handle to plotted data set(h_values, 'XData', R(~I), 'YData', S(~I)); %// remove failures h_axes = scatterhist(R, S); set(h_axes(3), 'XDir', 'Reverse') hold on plot(R(I), S(I), 'r.', 'markersize', 20); %// put failures back, in red xlabel('R'),ylabel('S')` Didn't work. Thanks a lot for the help! – user3641311 Oct 14 '14 at 21:11
  • Please do try the code in my last comnent and tell me if it works – Luis Mendo Oct 14 '14 at 21:13
  • Just this: `figure h_axes = scatterhist(R, S); set(h_axes(3), 'XDir', 'Reverse')` didn't work. Sorry mate. – user3641311 Oct 14 '14 at 21:17
  • 1
    Well, it works for me. I can't reproduce your problem. Maybe try `set(h_axes(1), 'XDir', 'Reverse')` (perhaps axis ordering is different in your Matlab version) – Luis Mendo Oct 14 '14 at 21:20
  • WORKED! :) Thanks a lot mate! And to bother you so much! :) Regards – user3641311 Oct 14 '14 at 21:22
  • :-) I learned something along the way too: not to trust axis ordering produced by Matlab functions – Luis Mendo Oct 14 '14 at 21:22
  • 1
    Funny joke! :) At least, all the effort was rewarded for the both of us! ;) Regards – user3641311 Oct 14 '14 at 21:26