#! /usr/bin/python3 # ================================================================== # Print Hsitogram Using My crude/dumb plot # # Note: # # 1. this code uses a very crude/dumb plot technique # 2. take note which value is x and which value is y # in the data and which axis shows which values # # ================================================================== import numpy # ---- size of plot area plotx = 40 ploty = 40 # ---- plot character plotc = '*' # ---- plot data (x,y) data = [ (100,245), (200,300), (300,20), (400,700), (500,34), (60,400), (700,44), (80,333), (900,333), (1000,1000) ] # ---- plot x/y min/max xmin = None xmax = None ymin = None ymax = None for t in data: # ---- x minimum if xmin == None: xmin = t[0] else: if t[0] < xmin: xmin = t[0] # --- x maximum if xmax == None: xmax = t[0] else: if t[0] > xmax: xmax = t[0] # --- y minimum if ymin == None: ymin = t[1] else: if t[1] < ymin: ymin = t[1] # --- y maximum if ymax == None: ymax = t[1] else: if t[1] > ymax: ymax = t[1] print("") print("---- data max/min -------------------------\n") print("xmin = {}".format(xmin)) print("xmax = {}".format(xmax)) print("ymin = {}".format(ymin)) print("ymax = {}".format(ymax)) # ---- plot data - only scale x print("") print("---- histogram ----------------------------\n") for t in data: n = int((t[0]/xmax) * plotx) ##print("n = {} (x={})".format(n,t[0])) print("{:>6} | {}".format(t[1],plotc*n))