How to edit histograms?

5 次查看(过去 30 天)
Hello guys! I have Data Mining class and in order to prepare my report I have to know more about histograms.
I have a file, which I attach this thread, showing a log which belongs to a phone company. The last column ("churn") indicates that if the user resigned from the operator or not. My mission is to find interesting relationships showing why user have resigned from the operator. For example, I choose one of the columns (e.g Day Mins) and examine it. If people who has lots of day mins tend to resign, I have to prove this.
I want to plot an histogram for indicating that. I have the information of who has resigned or not as true or false values. So how can I split each bar into two bars. A single bar will contain two bars. One bar at the down is people who have resigned and the other bar at the top will be the people who did not resign. In attachment I also giving you the plot that I made.

采纳的回答

AJ von Alt
AJ von Alt 2014-1-17
You can plot multiple histograms on a single set of axes using the hold command.
If I understand you correctly you want a histogram that looks like this:
This can be achieved by using hold to overlay the resigned histogram over the total histogram.
To do so plot your first histogram:
bar( centers , n , 'b' )
Turn on hold to prevent overwriting the first histogram:
hold on
Plot your second histogram:
bar( centers , n2 , 'r' )
Finally, turn off hold when your are done:
hold off
The following code gives you an example for two randomly generated data sets dayMinsUnresigned and dayMinsResigned. To use this code with your data you will first have to sort dayMins into the two vectors. Logical indexing would be a good place to get started with that.
%Inputs
dayMinsUnresigned = 10*rand(1 , 100);
dayMinsResigned = 10*rand(1 , 100);
%Histogram for each input using the same centers
[nUnresigned , minuteCenters] = hist( dayMinsUnresigned );
nResigned = hist( dayMinsResigned, minuteCenters );
%Sum the bins so that the second data set appears above the first
nSum = nUnresigned + nResigned;
figure;
bar(minuteCenters , nSum , 'b' ) %create the total histogram
% turn on hold so you can add another histogram to the same axis
hold on
bar(minuteCenters , nResigned , 'r' )
% do not forget to turn off hold when you're done!
hold off
legend('Not Resigned' , 'Resigned' )

更多回答(1 个)

Bora Semiz
Bora Semiz 2014-1-17
I am really appreciated. Thanks :)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by