Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's an algorithm of point diagram, as simple and naive as it could be. Of course, its performance is far from being performed and could be optimized, as well as the output could have some axes and numbers on it.</p> <pre><code>HEIGHT = 10 WIDTH = 40 MARKER = '*' FILL_CHARACTER = ' ' coords = [(ch[0], ch[3]) for ch in band1.values()] # Convert to coordinates of a desired ASCII area xmin = min(c[0] for c in coords) xmax = max(c[0] for c in coords) kx = (WIDTH - 1) / (xmax - xmin) ymin = min(c[1] for c in coords) ymax = max(c[1] for c in coords) ky = (HEIGHT - 1) / (ymax - ymin) acoords = [(round((c[0] - xmin) * kx), round((c[1] - ymin) * ky)) for c in coords] # Actually draw the graph for y in range(HEIGHT, -1, -1): chars = [] for x in range(WIDTH): if (x, y) in acoords: chars.append(MARKER) else: chars.append(FILL_CHARACTER) print(''.join(chars)) </code></pre> <p>Results to:</p> <pre><code> * * * * * * * * * * * * </code></pre> <p>If x coordinates are unique, it can be quite easily modified to draw column or line diagrams.</p> <p>E.g. for case of bars:</p> <pre><code>HEIGHT = 10 WIDTH = 40 MARKER = '*' FILL_CHARACTER = ' ' coords = [(ch[0], ch[3]) for ch in band1.values()] coords.sort(key=lambda ch: ch[1]) xmin = min(c[0] for c in coords) xmax = max(c[0] for c in coords) kx = (WIDTH - 1) / (xmax - xmin) ymin = min(c[1] for c in coords) ymax = max(c[1] for c in coords) ky = (HEIGHT - 1) / (ymax - ymin) acoords = {} for c in coords: x = round((c[0] - xmin) * kx) y = round((c[1] - ymin) * ky) if x not in acoords: acoords[x] = y else: acoords[x] = max(acoords[x], y) for y in range(HEIGHT, -1, -1): chars = [] for x in range(WIDTH): if acoords.get(x, 0) &gt;= y: chars.append(MARKER) else: chars.append(FILL_CHARACTER) print(''.join(chars)) </code></pre> <p>Results to:</p> <pre><code> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **************************************** </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload