Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build system information #63

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
fmt and lint w ruff
  • Loading branch information
tammoippen committed Dec 20, 2024
commit 77c03bfc00d15f4f2a3459bf1853de5b6ec310a8
77 changes: 49 additions & 28 deletions examples/color_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



# The MIT License

# Copyright (c) 2017 - 2024 Tammo Ippen, [email protected]
Expand Down Expand Up @@ -29,35 +26,59 @@


def main():
print(color('Do not print colors, if `no_color` is set to True', fg='red', no_color=True))
print(color('You can set a foreground', fg='red'))
print(color('and a background.', bg='red'))
print(color('Or both.', fg='black', bg='cyan'))

print(color('Asside from 4-bit / name colors', fg='green', mode='names'))
print(color('you can also set 8-bit colors / 256-color lookup tables', fg=126, bg=87, mode='byte'))
print(color('or go with full 24-bit rgb colors', fg=(50, 50, 50), bg=(166, 237, 240), mode='rgb'))

no_color = os.environ.get('NO_COLOR')
os.environ['NO_COLOR'] = '1'
print(color('The Environmnet variable `NO_COLOR` will always strip colors.', fg='red'))
print(
color(
"Do not print colors, if `no_color` is set to True", fg="red", no_color=True
)
)
print(color("You can set a foreground", fg="red"))
print(color("and a background.", bg="red"))
print(color("Or both.", fg="black", bg="cyan"))

print(color("Asside from 4-bit / name colors", fg="green", mode="names"))
print(
color(
"you can also set 8-bit colors / 256-color lookup tables",
fg=126,
bg=87,
mode="byte",
)
)
print(
color(
"or go with full 24-bit rgb colors",
fg=(50, 50, 50),
bg=(166, 237, 240),
mode="rgb",
)
)

no_color = os.environ.get("NO_COLOR")
os.environ["NO_COLOR"] = "1"
print(
color("The Environmnet variable `NO_COLOR` will always strip colors.", fg="red")
)
if no_color:
os.environ['NO_COLOR'] = no_color
os.environ["NO_COLOR"] = no_color
else:
os.environ.pop('NO_COLOR')

force_color = os.environ.get('FORCE_COLOR')
os.environ['FORCE_COLOR'] = '1'
print(color('The Environmnet variable `FORCE_COLOR` allows to toggle colors,', fg='blue'))
os.environ['FORCE_COLOR'] = '0'
print(color('setting it to 0, none or false, strips color codes', fg='magenta'))
os.environ['FORCE_COLOR'] = '1'
print(color('everything else forces color codes', fg='green'))
os.environ.pop("NO_COLOR")

force_color = os.environ.get("FORCE_COLOR")
os.environ["FORCE_COLOR"] = "1"
print(
color(
"The Environmnet variable `FORCE_COLOR` allows to toggle colors,", fg="blue"
)
)
os.environ["FORCE_COLOR"] = "0"
print(color("setting it to 0, none or false, strips color codes", fg="magenta"))
os.environ["FORCE_COLOR"] = "1"
print(color("everything else forces color codes", fg="green"))
if force_color:
os.environ['FORCE_COLOR'] = force_color
os.environ["FORCE_COLOR"] = force_color
else:
os.environ.pop('FORCE_COLOR')
os.environ.pop("FORCE_COLOR")


if __name__ == '__main__':
if __name__ == "__main__":
main()
11 changes: 4 additions & 7 deletions examples/custom_ticks_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



# The MIT License

# Copyright (c) 2017 - 2024 Tammo Ippen, [email protected]
Expand Down Expand Up @@ -51,12 +48,12 @@ def mean_y_value(Y, min_, max_):


def str_tick(min_, max_):
return '{:.3f}'.format(min_ + (max_ - min_) / 2)
return "{:.3f}".format(min_ + (max_ - min_) / 2)


def main():
Y = [0, 10, 20, 20, 21, 25, 30, 32, 40, 44, 50] + [51.3] * 10 # noqa: N806
X = list(range(len(Y))) # noqa: N806
Y = [0, 10, 20, 20, 21, 25, 30, 32, 40, 44, 50] + [51.3] * 10
X = list(range(len(Y)))

fig = plt.Figure()
fig.plot(X, Y)
Expand All @@ -82,5 +79,5 @@ def main():
print(fig.show())


if __name__ == '__main__':
if __name__ == "__main__":
main()
25 changes: 14 additions & 11 deletions examples/ellipse_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



# The MIT License

# Copyright (c) 2017 - 2024 Tammo Ippen, [email protected]
Expand Down Expand Up @@ -35,36 +32,42 @@ def main():
fig.width = 50
fig.height = 20

X1, Y1 = plt_data.ellipse(x_center=0, y_center=0, x_amplitude=0.5, y_amplitude=0.5, n=20) # noqa: N806
X1, Y1 = plt_data.ellipse(
x_center=0, y_center=0, x_amplitude=0.5, y_amplitude=0.5, n=20
)
fig.plot(X1, Y1)

print(fig.show(legend=True))

# first set
X2, Y2 = plt_data.ellipse(x_center=0, y_center=0) # noqa: N806
X2, Y2 = plt_data.ellipse(x_center=0, y_center=0)
fig.plot(X2, Y2)

X3, Y3 = plt_data.ellipse(x_center=0, y_center=0, x_amplitude=0.5, y_amplitude=0.5, n=20) # noqa: N806
fig.plot(X3, Y3, label='Ellipse 2')
X3, Y3 = plt_data.ellipse(
x_center=0, y_center=0, x_amplitude=0.5, y_amplitude=0.5, n=20
)
fig.plot(X3, Y3, label="Ellipse 2")

print(fig.show(legend=True))

# second set, offset
fig.clear()
X2, Y2 = plt_data.ellipse(x_center=0, y_center=0) # noqa: N806
X2, Y2 = plt_data.ellipse(x_center=0, y_center=0)
fig.plot(X2, Y2)
fig.set_x_limits(min_=-10, max_=10)
fig.set_y_limits(min_=-10, max_=10)

for xx in [-4, 0, 4]:
for yy in [-4, 0, 4]:
X, Y = plt_data.ellipse(x_center=xx, y_center=yy, x_amplitude=1, y_amplitude=1, n=20) # noqa: N806
fig.plot(X, Y, label=('{},{}'.format(xx, yy)))
X, Y = plt_data.ellipse(
x_center=xx, y_center=yy, x_amplitude=1, y_amplitude=1, n=20
)
fig.plot(X, Y, label=("{},{}".format(xx, yy)))

fig.scatter([4], [4])

print(fig.show(legend=True))


if __name__ == '__main__':
if __name__ == "__main__":
main()
9 changes: 3 additions & 6 deletions examples/histograms_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



# The MIT License

# Copyright (c) 2017 - 2024 Tammo Ippen, [email protected]
Expand Down Expand Up @@ -33,12 +30,12 @@


def main():
print('Histogram left to right')
print("Histogram left to right")
print(plotille.hist(np.random.normal(size=10000)))

print('Histogram rotated')
print("Histogram rotated")
print(plotille.histogram(np.random.normal(size=10000)))


if __name__ == '__main__':
if __name__ == "__main__":
main()
11 changes: 4 additions & 7 deletions examples/house_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



# The MIT License

# Copyright (c) 2017 - 2024 Tammo Ippen, [email protected]
Expand All @@ -25,21 +22,21 @@

from plotille import Canvas


# The underlying canvas-implementation can be used on its own.


def main():
c = Canvas(width=40, height=20)
c.rect(0.1, 0.1, 0.6, 0.6)
c.line(0.1, 0.1, 0.6, 0.6)
c.line(0.1, 0.6, 0.6, 0.1)
c.line(0.1, 0.6, 0.35, 0.8)
c.line(0.35, 0.8, 0.6, 0.6)
c.text(0.3, 0.5, 'hi', color='red')
c.point(0.35, 0.35, color='blue')
c.text(0.3, 0.5, "hi", color="red")
c.point(0.35, 0.35, color="blue")
c.fill_char(0.35, 0.1)
print(c.plot())


if __name__ == '__main__':
if __name__ == "__main__":
main()
40 changes: 19 additions & 21 deletions examples/images_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



# The MIT License

# Copyright (c) 2017 - 2024 Tammo Ippen, [email protected]
Expand All @@ -27,33 +24,32 @@

try:
from PIL import Image
except ImportError:
raise Exception('Need to have PIL / pillow installed for this example.')
except ImportError as e:
raise Exception("Need to have PIL / pillow installed for this example.") from e

from plotille import Canvas, Figure


current_dir = os.path.dirname(os.path.abspath(__file__))


def canvas_dots():
# Canvas on its own can draw an image using dots
img = Image.open(current_dir + '/../imgs/ich.jpg')
img = img.convert('L')
img = Image.open(current_dir + "/../imgs/ich.jpg")
img = img.convert("L")
img = img.resize((80, 80))
cvs = Canvas(40, 20)
cvs.braille_image(img.getdata())

print('\nImage with braille dots:')
print("\nImage with braille dots:")
print(cvs.plot())


def figure_image():
# Figure can draw an image using the background color of characters
width = 80
height = 40
img = Image.open(current_dir + '/../imgs/ich.jpg')
img = img.convert('RGB')
img = Image.open(current_dir + "/../imgs/ich.jpg")
img = img.convert("RGB")
img = img.resize((width, height))
# we need the data as height x width array of rgb values
data = img.getdata()
Expand All @@ -63,34 +59,36 @@ def figure_image():
fig.width = width
fig.height = height
# only rgb and byte are supported right now
fig.color_mode = 'byte'
fig.color_mode = "byte"

fig.imgshow(data)

print('\nImage with rgb values in the background:')
print("\nImage with rgb values in the background:")
print(fig.show())


def figure_cmap():
# Figure can draw an image using the background color of characters
width = 80
height = 40
img = Image.open(current_dir + '/../imgs/ich.jpg')
img = Image.open(current_dir + "/../imgs/ich.jpg")
# only luminance here
img = img.convert('L')
img = img.convert("L")
img = img.resize((width, height))
# we need the data as height x width array of luminance values
data = img.getdata()
data = [[data[row * width + col] for col in range(width)] for row in range(height)]

for cmap in ['gray', 'plasma']:
for cmap in ["gray", "plasma"]:
fig = Figure()
fig.width = width
fig.height = height
# only rgb and byte are supported right now
fig.color_mode = 'byte'
fig.color_mode = "byte"

print('\nImage with luminance values only in the background using "{}" cmap:'.format(cmap))
print(
f'\nImage with luminance values only in the background using "{cmap}" cmap:'
)
fig.imgshow(data, cmap=cmap)

print(fig.show())
Expand All @@ -110,12 +108,12 @@ def figure_cmap_handcrafted():
data[20 + y][40 + x] = 20 - x - y
data[20 + y][40 - x] = 20 - x - y

for cmap in ['gray', 'plasma']:
for cmap in ["gray", "plasma"]:
fig = Figure()
fig.width = width
fig.height = height
# only rgb and byte are supported right now
fig.color_mode = 'byte'
fig.color_mode = "byte"

print('\nSome data using color in the background using "{}" cmap:'.format(cmap))
fig.imgshow(data, cmap=cmap)
Expand All @@ -133,5 +131,5 @@ def main():
figure_cmap_handcrafted()


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading
Loading