GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #33 from ga7g08/Adds-color-support-to-scatter-plot · NeelShah18/bashplotlib@fdc52be

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bashplotlib
    • scatterplot.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bashplotlib/scatterplot.py‎

Copy file name to clipboardExpand all lines: bashplotlib/scatterplot.py
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def get_scale(series, is_y=False, steps=20):
1717
min_val = min(series)
1818
max_val = max(series)
1919
scaled_series = []
20-
for x in drange(min_val, max_val, (max_val - min_val) / steps):
20+
for x in drange(min_val, max_val, (max_val - min_val) / steps,
21+
include_stop=True):
2122
if x > 0 and scaled_series and max(scaled_series) < 0:
2223
scaled_series.append(0.0)
2324
scaled_series.append(x)
@@ -45,9 +46,13 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
4546
if isinstance(f, str):
4647
f = open(f)
4748

48-
data = [tuple(map(float, line.strip().split(','))) for line in f]
49-
xs = [i[0] for i in data]
50-
ys = [i[1] for i in data]
49+
data = [tuple(line.strip().split(',')) for line in f]
50+
xs = [float(i[0]) for i in data]
51+
ys = [float(i[1]) for i in data]
52+
if len(data[0]) > 2:
53+
cs = [i[2].strip() for i in data]
54+
else:
55+
cs = None
5156
else:
5257
xs = [float(str(row).strip()) for row in open(xs)]
5358
ys = [float(str(row).strip()) for row in open(ys)]
@@ -65,16 +70,11 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
6570
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
6671
if xp <= x and yp >= y and (xp, yp) not in plotted:
6772
point = pch
68-
#point = str(i)
6973
plotted.add((xp, yp))
70-
if x == 0 and y == 0:
71-
point = "o"
72-
elif x == 0:
73-
point = "|"
74-
elif y == 0:
75-
point = "-"
74+
if cs:
75+
colour = cs[i]
7676
printcolour(point, True, colour)
77-
print("|")
77+
print(" |")
7878
print("-" * (2 * len(get_scale(xs, False, size)) + 2))
7979

8080

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.