GDI Objects

Extend existing charts and create new visualizations.

 

arc


def arc(
   center:tuple|list, 
   p1:tuple|list, 
   p2:tuple|list,
   label:str = "",
   **kwargs)->int:
"""
center: (x, y) -> center point of arc
p1: (x1, y1) -> start of arc
p2: (x2, y2) -> end of arc
label: if not empty str object will be displayed at legend

---
1) The arc is drawn in a counter-clockwise direction between the start and the end points.
2) To plot a circular arc, the plot area must be a square.
"""

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi

plt.canvas(x=[1,7], y=[2,6])

c, p1, p2 = (4,3), (6, 3), (2,3)

gdi.arc(center=c , p1=p1, p2=p2, fc="#00FF00")
gdi.text(xy=c, label="C")
gdi.text(xy=p1, label="p1")
gdi.text(xy=p2, label="p2")

plt.show()
Half circle

 

 

arrow


def arrow(
   p1:tuple|list, 
   p2:tuple|list, 
   angle:numbers.Real = 45, #45 degrees
   length:float = 0.1, #10% length of main-line
   label:str = "",
   **kwargs)->int:
"""
p1, p2: (x1, y1), (x2, y2) coordinate of the main-line
angle: angle between the two head-lines
length: ratio of the length of the head-line to the main-line
label: if not empty str object will be displayed at legend
"""

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi
from random import randrange as rr
from math import cos, sin, radians

plt.canvas(x=[-5,5], y=[-5,5])

r1, r2 = 1.0, 4.0

p=lambda r, d: [r*cos(radians(d)), r*sin(radians(d))]
for i in range(0, 360, 45):
	color = [rr(0, 255), rr(0, 255), rr(0, 255)]
	gdi.arrow(p(r1, i), p(r2, i), ec=color, lw=3)

plt.show()
Rotated arrows

 

 

curve


def curve(
   x:Iterable, 
   y:Iterable, 
   label:str = "",
   **kwargs)->int:
"""
Draws a smooth curve between (x1, y1), (x2, y2), ..., (xn, yn). 
The curve is only guaranteed to pass from (x1, y1) and (xn, yn).

x, y: (x,y) values
label: if not empty str object will be displayed at legend
"""

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi
import numpy as np

# Equation: https://mathworld.wolfram.com/HeartCurve.html
t= np.linspace(-10, 10, 1000)
x = 16*np.sin(t)**3
y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cos(3*t)-np.cos(4*t)

plt.canvas(x=[-20, 20], y=[-20, 20], 
	haxis=False, vaxis=False, #axes are not shown
	hgrid=False, vgrid=False) #gridlines are not shown

gdi.curve(x, y, ec="#FF0000")
gdi.text((-4.5,-4), "Thank You", 45, 
			fontsize=25, 
			fontcolor="#00FF00")

plt.show()
Heart curve

 

 

ellipse


def ellipse(
   xy:tuple|list, 
   width:numbers.Real, 
   height:numbers.Real, 
   label:str = "",
   **kwargs)->int:
"""
xy: 	(x, y), center,
width: 	half width (>0),
height: half height (>0),
label: if not empty str object will be displayed at legend
"""

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi

plt.canvas(x=[-5,5], y=[-5,5])

#height = width (circle)
gdi.ellipse(xy=(0,-2), width=2, height=2, lw=2)

#height and width are different
gdi.ellipse(xy=(0,2.2), width=3, height=2, ec="#FF0000", lw=2)

plt.show()
Circle and ellipse

 

 

line


def line(
   p1:tuple|list, 
   p2:tuple|list, 
   label:str = "",
   **kwargs)->int:
"""
p1: (x1, y1)
p2: (x2, y2)
label: if not empty str object will be displayed at legend
""" 

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi

plt.canvas(x=[-5,5], y=[-5,5])

gdi.line(p1=[-3,-3], p2=[-3, 3], lw=3)
gdi.line(p1=[3, -3], p2=[3,3], ec="0 10 255", lw=3, ls="--")
gdi.line(p1=[-3,0], p2=[3,0], lw=3, ls=":", ec="255 0 0")
plt.show()
Lines

 

 

marker


def marker(
   xy:tuple|list, 
   type:str = "c",
   size:int = 5,
   label:str = "",
   **kwargs)->int:
"""
xy:	(x, y), centroid,
type: type of the marker, "c", "t", "r", "x",
size: size of the marker in pixels
label: if not empty str object will be displayed at legend
"""

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi
import numpy as np
import math

measurement = [0, 20, 50] #temperatures

#Energy absorbed at different temperatures
data = np.array([
	[52, 58, 82, 35, 84], #0C
	[48, 66, 74, 86, 78], #20
	[73.5, 82, 72, 80, 79] #50C
])

mean  = np.mean(data, axis=1)
std = np.std(data, axis=1, ddof=1)
se = std/ math.sqrt(data.shape[1])

plt.canvas(x=[-10,60], y=[40,90])
for i in range(len(measurement)):
   x1 = measurement[i]
   x2 = x1
   y1, y2 = mean[i] + se[i], mean[i] - se[i]
   gdi.line([x1, y1], [x2, y2], ls = "--", lw=2, ec="#FF0000")

   gdi.marker(xy=(x1,mean[i]))

plt.show()
Scatter chart with error bars

 

 

polygon


def polygon(
   xy:_Iterable, 
   label:str = "",
   **kwargs)->int:
"""
Draws a polygon between (x1, y1), (x2, y2), ..., (xn, yn). 
The first and last points are automatically closed.

At least 3 points expected.

 --------
label: if not empty str object will be displayed at legend
"""

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi

plt.canvas(x=[0,6], y=[0,4])

x, y = [1,3,5], [1,3,1]

#alternatively: list(zip(x,y))
xy = [(1,1), (3,3), (5,1)]

gdi.polygon(xy=xy, fc="#FF12AA")

plt.show()
Triangle

 

 

rect


def rect(
   xy:tuple|list, 
   width:numbers.Real, 
   height:numbers.Real, 
   label:str = "",
   **kwargs)->int:
"""
xy:	(x, y), bottom-left corner of the rectangle,
width: 	width of rectangle (>0),
height: height of rectangle (>0), 
label: if not empty str object will be displayed at legend
"""	

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi

plt.canvas(x=[-5,5], y=[-5,5])

gdi.rect(
	[-4, -3], 
	width=3, 
	height=4, 
	ec="20 50 100", 
	lw=2, 
	ls="--")

gdi.rect(
	[0, -1], 
	width=4, 
	height=3, 
	ec="#FF0000", 
	lw=2, 
	fc="0 255 255", 
	hatch="/")
plt.show()
Rectangles

 

 

text


def text(
   xy:tuple|list, 
   label:str,
   rotation:float = 0.0,
   hanchor:str = "l",
   vanchor:str = "t",
   **kwargs)->int:
"""
xy: (x, y), top-left,
label: text to be drawn,
rotation: rotation in degrees (>0 is counter-clockwise)
hanchor: horizontal anchor, "l", "c" "r" for left, center, right.
vanchor: vertical anchor, "t", "c", "b" for top, center and bottom
labelcolor: label color
"""

Examples


import scisuitplot as plt
import scisuitplot.gdi as gdi

plt.canvas(x=[-5,5], y=[-5,5])

angles = range(0, 360, 45)
r = 1
for alpha in angles:
   rad = alpha*math.pi/180
   loc = [r*math.cos(rad), r*math.sin(rad)]
   gdi.text(loc, label="Hello Python", rotation=alpha)
plt.show()
Rotated texts

 

 

makegroup


def makegroup(
   owner:int, 
   members:Iterable[int])->None:
"""
sets the properties of members based on owner's properties

## Inputs:
owner: A gdi object whose properties will affect members' properties,
members: gdi object(s) whose properties will be synched with owner

## Note: 
This function is rather useful (meaningful) if properties will be manipulated at runtime.
"""

If members have label parameter set, they will still be displayed at legend of the chart; however, they will not be displayed on the window (shown when right-clicked on legend and "Change Visibility" option selected) which allows manipulation of the visibility of the objects.