MATLAB pie chart and histogram

  1. Pie chart
  • pie(x): Draw a pie chart of data x. x can be a vector or a matrix. Each element in x will represent a sector of the pie chart, and the pie chart will show the proportion of the sum of the elements.
  • pie(x, explode): Draw a pie chart of data x, where the parameter explode can be used to set an important sector in the pie chart for extractive and focused display. It should be noted that the length of the explode vector is the same as that in x The number of elements is equal and corresponds to the meaning of the elements in x. The explode element has a non-zero value, and the corresponding element sectors will be displayed separately from the pie chart. Normally, the non-zero values ​​are set to 1.
  • pie (x, labels): draw a pie chart data x, where labels can be used to set display parameters for each sector of the pie chart labels, labels should be noted that the parameter vector X using the data in the pie chart is depicted a string or number
    Example : For a graduate student, the average monthly expenses in a year are 190 yuan for living expenses, 33 yuan for materials, 45 yuan for telephone charges, 42 yuan for clothes purchase, and 45 yuan for other expenses. Please use a pie chart to show his monthly consumption ratio, and separate the slices with the most used expenses and the least used expenses in the pie chart.
    x=[190 33 45 42 45];
    % separate display settings
    explode=[1 1 0 0 0];
    % drawing
    figure()
    colormap hsv
    pie(x,explode,{'living expenses','data expenses','phone expenses ','Purchase clothes','Other expenses'})
    title('Pie chart')
    Insert picture description here
    % The random function generates a 5*3 array, and
    rounds the generated data Y = round(rand(5,3)*10);
    % Plotting
    subplot(2,2,1)
    bar(Y,'group') title'Group
    '
    % Heap two-dimensional vertical bar graph
    subplot(2,2,2)
    bar(Y,'stack')
    title(' Stack')
    %Heap type two-dimensional horizontal bar graph
    subplot(2,2,3)
    barh(Y,'stack')
    title('Stack')
    % Set the width of the bar to 1.5
    subplot(2,2,4)
    bar(Y,1.5)
    title('Width = 1.5')
    Insert picture description here
    CSDN: Mathematical modeling summary of MATLAB drawing

Guess you like

Origin blog.csdn.net/m0_38127487/article/details/114082524