Hướng dẫn dùng image histogram trong PHP
It is a script to draw a simple histogram like Photoshop does (only similar, because I suspect it scale both axes with a sigmoid function, or something like that). Show
I wrote a
Note I'm not checking if filename exist, neither if Nội dung chính
DescriptionHistograms are a type of bar plot for numeric data that group the data into bins. After you create a CreationSyntaxDescriptionexample
example
example
example
example
example
Input Argumentsexpand all X — Data to distribute among bins vector | matrix | multidimensional arrayData to distribute among bins, specified as a vector, matrix, or
multidimensional array. If
Note If Data Types: C — Categorical data categorical arrayCategorical data, specified as a categorical array. Data Types: nbins — Number of bins positive integerNumber of bins, specified as a positive integer. If you do not specify Example: edges — Bin edges vectorBin edges, specified as a vector. The value For datetime and duration data, Data Types: Note This option only applies to categorical histograms. Categories included in histogram, specified as a cell array of character vectors, categorical array, or string array.
Example: Example: Example: Data Types: counts — Bin counts vectorBin counts, specified as a vector. Use this input to pass bin counts to The length of
Example: Example: ax — Target axes Axes object | PolarAxes objectTarget axes, specified as an Name-Value Arguments Specify optional pairs of arguments as Before R2021a, use commas to separate each name and value, and enclose Example:
The histogram properties listed here are only a subset. For a complete list, see Histogram Properties. Note This option only applies to histograms of categorical data. Relative width of categorical bars, specified as a scalar value in the range If you set this property to Example: Data Types: Bin limits, specified as a two-element vector, This option does not apply to histograms of categorical data. Example: Selection mode for bin limits, specified as If you explicitly specify either
This option does not apply to histograms of categorical data. Binning algorithm, specified as one of the values in this table.
For datetime data, the bin method can be one of these units of time:
For duration data, the bin method can be one of these units of time:
If you specify This option does not apply to histograms of categorical data. Note If you set the Example:
Width of bins, specified as a scalar. When you specify For datetime and duration data, the value of This option does not apply to histograms of categorical data. Example: Category display order, specified as This option only works with categorical data. Histogram display style, specified as either The default value of Example: EdgeAlpha — Transparency of histogram bar edges 1 (default) | scalar value between 0 and 1 inclusiveTransparency of histogram bar edges,
specified as a scalar value between Example: EdgeColor — Histogram edge color [0 0 0] or black (default) | 'none' | 'auto' | RGB triplet | hexadecimal color code | color nameHistogram edge color, specified as one of these values:
Example: FaceAlpha — Transparency of histogram bars 0.6 (default) | scalar value between 0 and 1 inclusiveTransparency of histogram bars, specified as a scalar value between Example: FaceColor — Histogram bar color 'auto' (default) | 'none' | RGB triplet | hexadecimal color code | color nameHistogram bar color, specified as one of these values:
If you specify Example: Line style, specified as one of the options listed in this table.
Width of bar outlines, specified as a positive value in point units. One point equals 1/72 inch. Example: Data Types: Type of normalization, specified as one of the values in this table. For each bin
Example: Number of categories to display, specified as a scalar. You can change the ordering of categories displayed in the histogram using the This option only works with categorical data. Orientation of bars, specified as Example: Toggle
summary display of data belonging to undisplayed categories, specified as Set this option to You can change the number of categories displayed in the histogram, as well as their order, using the This option only works with categorical data. PropertiesObject FunctionsExamplescollapse all Histogram of VectorGenerate 10,000 random numbers and create a histogram. The x = randn(10000,1); h = histogram(x) h = Histogram with properties: Data: [10000x1 double] Values: [2 2 1 6 7 17 29 57 86 133 193 271 331 421 540 613 ... ] NumBins: 37 BinEdges: [-3.8000 -3.6000 -3.4000 -3.2000 -3 -2.8000 -2.6000 ... ] BinWidth: 0.2000 BinLimits: [-3.8000 3.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties When you specify an output argument to the Find the number of histogram bins. Specify Number of Histogram BinsPlot a histogram of 1,000 random numbers sorted into 25 equally spaced bins. x = randn(1000,1); nbins = 25; h = histogram(x,nbins) h = Histogram with properties: Data: [1000x1 double] Values: [1 3 0 6 14 19 31 54 74 80 92 122 104 115 88 80 38 32 ... ] NumBins: 25 BinEdges: [-3.4000 -3.1200 -2.8400 -2.5600 -2.2800 -2 -1.7200 ... ] BinWidth: 0.2800 BinLimits: [-3.4000 3.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties Find the bin counts. counts = 1×25
1 3 0 6 14 19 31 54 74 80 92 122 104 115 88 80 38 32 21 9 5 5 5 0 2
Change Number of Histogram BinsGenerate 1,000 random numbers and create a histogram. X = randn(1000,1); h = histogram(X) h = Histogram with properties: Data: [1000x1 double] Values: [3 1 2 15 17 27 53 79 85 101 127 110 124 95 67 32 27 ... ] NumBins: 23 BinEdges: [-3.3000 -3.0000 -2.7000 -2.4000 -2.1000 -1.8000 ... ] BinWidth: 0.3000 BinLimits: [-3.3000 3.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties Use the Nbins = morebins(h); Nbins = morebins(h) Adjust the bins at a fine grain level by explicitly setting the number of bins. Specify Bin Edges of HistogramGenerate 1,000 random numbers and create a histogram. Specify the bin edges as a vector with wide bins on the edges of the histogram to capture the outliers that do not satisfy |x|<2. The first vector element is the left edge of the first bin, and the last vector element is the right edge of the last bin. x = randn(1000,1); edges = [-10 -2:0.25:2 10]; h = histogram(x,edges); Specify the h.Normalization = 'countdensity'; Plot Categorical HistogramCreate a categorical vector that represents votes. The categories in the vector are A = [0 0 1 1 1 0 0 0 0 NaN NaN 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1]; C = categorical(A,[1 0 NaN],{'yes','no','undecided'}) C = 1x27 categorical
Columns 1 through 9
no no yes yes yes no no no no
Columns 10 through 16
undecided undecided yes no no no yes
Columns 17 through 25
no yes no yes no no no yes yes
Columns 26 through 27
yes yes
Plot a categorical histogram of the votes, using a relative bar width of h = histogram(C,'BarWidth',0.5) h = Histogram with properties: Data: [no no yes yes yes no no ... ] Values: [11 14 2] NumDisplayBins: 3 Categories: {'yes' 'no' 'undecided'} DisplayOrder: 'data' Normalization: 'count' DisplayStyle: 'bar' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties Histogram with Specified NormalizationGenerate 1,000 random numbers and create a histogram using the x = randn(1000,1); h = histogram(x,'Normalization','probability') h = Histogram with properties: Data: [1000x1 double] Values: [0.0030 1.0000e-03 0.0020 0.0150 0.0170 0.0270 0.0530 ... ] NumBins: 23 BinEdges: [-3.3000 -3.0000 -2.7000 -2.4000 -2.1000 -1.8000 ... ] BinWidth: 0.3000 BinLimits: [-3.3000 3.6000] Normalization: 'probability' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties Compute the sum of the bar heights. With this normalization, the height of each bar is equal to the probability of selecting an observation within that bin interval, and the height of all of the bars sums to 1. Plot Multiple HistogramsGenerate two vectors of random numbers and plot a histogram for each vector in the same figure. x = randn(2000,1);
y = 1 + randn(5000,1);
h2 = histogram(x);
hold on
h2 = histogram(y); Since the sample size and bin width of the histograms are different, it is difficult to compare them. Normalize the histograms so that all of the bar heights add to 1, and use a uniform bin width. h2.Normalization = 'probability'; h2.BinWidth = 0.25; h2.Normalization = 'probability'; h2.BinWidth = 0.25; Adjust Histogram PropertiesGenerate 1,000 random numbers and create a histogram. Return the histogram object to adjust the properties of the histogram without recreating the entire plot. x = randn(1000,1); h = histogram(x) h = Histogram with properties: Data: [1000x1 double] Values: [3 1 2 15 17 27 53 79 85 101 127 110 124 95 67 32 27 ... ] NumBins: 23 BinEdges: [-3.3000 -3.0000 -2.7000 -2.4000 -2.1000 -1.8000 ... ] BinWidth: 0.3000 BinLimits: [-3.3000 3.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties Specify exactly how many bins to use. Specify the edges of the bins with a vector. The first value in the vector is the left edge of the first bin. The last value is the right edge of the last bin. Change the color of the histogram bars. h.FaceColor = [0 0.5 0.5];
h.EdgeColor = 'r'; Determine Underlying Probability DistributionGenerate 5,000 normally distributed random numbers with a mean of 5 and a standard deviation of 2. Plot a histogram with x = 2*randn(5000,1) + 5; histogram(x,'Normalization','pdf') In this example, the underlying distribution for the normally distributed data is known. You can, however, use the The probability density function for a normal distribution with mean μ, standard deviation σ, and variance σ2 is f(x,μ ,σ)=1σ2π exp[-(x-μ)22σ2] . Overlay a plot of the probability density function for a normal distribution with a mean of 5 and a standard deviation of 2. hold on y = -5:0.1:15; mu = 5; sigma = 2; f = exp(-(y-mu).^2./(2*sigma^2))./(sigma*sqrt(2*pi)); plot(y,f,'LineWidth',1.5) Saving and Loading Histogram ObjectsUse the histogram(randn(10)); savefig('histogram.fig'); close gcf Use h = openfig('histogram.fig'); Use the y = findobj(h,'type','histogram') y = Histogram with properties: Data: [10x10 double] Values: [2 17 28 32 16 3 2] NumBins: 7 BinEdges: [-3 -2 -1 0 1 2 3 4] BinWidth: 1 BinLimits: [-3 4] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties Tips
Extended CapabilitiesTall Arrays Calculate with arrays that have more rows than fit in memory.This function supports tall arrays with the limitations:
For more information, see Tall Arrays for Out-of-Memory Data. GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.Usage notes and limitations:
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox). Distributed Arrays Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.Usage notes and limitations:
For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox). Version HistoryIntroduced in R2014b |