MCPcopy Create free account
hub / github.com/codechenx/FastTableViewer / getPlot

Method getPlot

stats.go:139–181  ·  view source on GitHub ↗

getPlot generates a histogram visualization for continuous data

()

Source from the content-addressed store, hash-verified

137
138// getPlot generates a histogram visualization for continuous data
139func (s *ContinuousStats) getPlot() string {
140 if len(s.data) == 0 {
141 return "No data to plot"
142 }
143
144 // Create histogram bins
145 numBins := 20
146 if len(s.data) < 100 {
147 numBins = 10
148 }
149 if len(s.data) < 20 {
150 numBins = 5
151 }
152
153 // Calculate bin width
154 binWidth := (s.max - s.min) / float64(numBins)
155 if binWidth == 0 {
156 return "All values are identical"
157 }
158
159 // Initialize bins
160 bins := make([]float64, numBins)
161
162 // Count values in each bin
163 for _, v := range s.data {
164 binIndex := int((v - s.min) / binWidth)
165 if binIndex >= numBins {
166 binIndex = numBins - 1
167 }
168 if binIndex < 0 {
169 binIndex = 0
170 }
171 bins[binIndex]++
172 }
173
174 // Generate the plot
175 plot := asciigraph.Plot(bins,
176 asciigraph.Height(15),
177 asciigraph.Width(60),
178 asciigraph.Caption("Distribution Histogram"))
179
180 return plot
181}
182
183func (s *DiscreteStats) summary(a []string) {
184 s.data = a

Calls

no outgoing calls