|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 2105 (0x839)
Types: TextFile
Names: »scatterplot.c«
└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
└─⟦this⟧ »cph85dist/stat/src/scatterplot.c«
/*LINTLIBRARY*/
#include "unixstat.h"
FUN(scatterplot,scatter plot,5.1,3/11/85)
/* Copyright (c) 1982 Gary Perlman (see Copyright file) */
#define W 12
#define D 3
#define MAX_WIDTH 100 /* plot at most this wide */
#define MAX_HEIGHT 100 /* plot at most this high */
#define EPSILON (.000000001)
#define scale(x,min,max,width) ((int) (width*((x)-(min))/((max)-(min)+EPSILON)))
scatterplot (x, y, n, plotchar, height, width, border)
float *x, *y;
{
double min_x = *x, min_y = *y;
double max_x = *x, max_y = *y;
int elt;
int col, row;
int plot[MAX_HEIGHT][MAX_WIDTH];
if (height > MAX_HEIGHT) height = MAX_HEIGHT;
if (width > MAX_WIDTH) width = MAX_WIDTH;
for (elt = 0; elt < n; elt++)
{
if (x[elt] < min_x) min_x = x[elt];
else if (x[elt] > max_x) max_x = x[elt];
if (y[elt] < min_y) min_y = y[elt];
else if (y[elt] > max_y) max_y = y[elt];
}
for (row = 0; row < height; row++)
for (col = 0; col < width; col++)
plot[row][col] = 0;
for (elt = 0; elt < n; elt++)
plot[scale(y[elt],min_y,max_y,height)][scale(x[elt],min_x,max_x,width)]++;
if (border)
{
putchar ('|');
for (col = 0; col < width; col++) putchar ('-');
putchar ('|');
if (border > 1) printf ("%g", max_y);
putchar ('\n');
}
for (row = height-1; row >= 0; row--)
{
if (border) putchar ('|');
for (col = 0; col < width; col++)
if (plot[row][col])
{
if (plotchar) putchar (plotchar);
else if (plot[row][col] >= 10) putchar ('*');
else putchar (plot[row][col]+'0');
}
else putchar (' ');
if (border) putchar ('|');
putchar ('\n');
}
if (border)
{
putchar ('|');
for (col = 0; col < width; col++) putchar ('-');
putchar ('|');
if (border > 1) printf ("%g", min_y);
putchar ('\n');
if (border > 1)
{
char dataline[MAX_WIDTH];
int len1, len2;
int i;
VOID sprintf (dataline, "%-.3f", min_x);
len1 = strlen (dataline);
printf ("%s", dataline);
VOID sprintf (dataline, "%.3f", max_x);
len2 = strlen (dataline);
for (i = len1+len2; i < width+2; i++)
putchar (' ');
puts (dataline);
}
}
}