Charts

Plot various charts.



bar, barh


def bar(
   x, 
   height, 
   width=0.8, 
   bottom=0.0, 
   color = None, 
   **kwargs):
"""
x: The x coordinates of the bars or category
height: The height of the bars.
width: The width of the bars.
bottom: The y coordinate of the bottom side of the bars.
"""



def barh(
   y, 
   width, 
   height=0.8, 
   left=0.0, 
   color = None, 
   **kwargs):
"""
y: The y coordinates of the bars or category
height: The height of the bars.
width: The width of the bars.
bottom: The y coordinate of the bottom side of the bars.
"""

Examples


import scisuitplot as plt

categ=["Q1", "Q2", "Q3", "Q4"]
A = [44, 55, 41, 67]
B = [13, 23, 8, 13]

plt.bar(x=categ, height=A, fc=(0,255,0), hatch="\\")
plt.bar(height=B, x=categ, lw=2, bottom=A)

plt.show()
Stacked bar chart

 


import scisuitplot as plt
import numpy as np

Categ = ("Control", "MW", "IR")
Levels = {
   'A': (18, 18, 14),
   'B': (38, 48, 47),
   'C': (189, 195, 217)}

x = np.arange(len(Categ))  # the label locations
width = 0.25  # the width of the bars
mult = 0

for key, measure in Levels.items():
   offset = width * mult
   plt.bar(x=x + offset, height=measure, width=width, label=key)
   mult += 1

plt.set_xticks(x+width, Categ)

plt.show()
Clustered bar chart

 

 



boxplot

Plots a box-whisker chart.


def boxplot(
   data:Iterable, 
   label:str|None = None, 
   **kwargs):
"""
data : Data to be plotted \n
label: Name of the series
"""

Examples


import scisuitplot as plt
x = [2, 1, 3, 6, 4]
y = [7, 7, 8, 4, 2]

plt.boxplot(data=x)
plt.boxplot(data=y)

plt.show()
Box-Whisker chart

Box-Whisker charts are interactive. Right-clicking on any of the box will show related context-menu options.

 

 



bubble

Plots a bubble chart.


def bubble(
   x:Iterable,
   y:Iterable,  
   s:Iterable,
   scale:float=1.0,
   color:str|tuple|list = (255, 0, 0),
   label:str=None):
"""
x, y, s:	x- and y- and size data
color: color
label: Name (currently not in use)
"""

 

Example


"""
Data adapted from:
https://developers.google.com/chart/interactive/docs/gallery/bubblechart
"""

import scisuitplot as plt
L = [80.66, 79.84, 78.6, 72.73, 80.05, 72.49, 68.09, 81.55, 68.6, 78.09]
F = [1.67, 1.36, 1.84, 2.78, 2, 1.7, 4.77, 2.96, 1.54, 2.05]
P = [337399, 819023, 55230, 797162, 618015, 731371, 310907, 74856, 1418500, 3070070]

plt.bubble(x=L, y=F, s=P)

plt.show()
Bubble chart

 

 



canvas


def canvas(
   x:Iterable, 
   y:Iterable,
   haxis = True,
   vaxis = True,
   hgrid = True,
   vgrid = True,
   scale = False):
"""
Shows a canvas (an empty chart with axes and gridlines)

## Input:
x: horizontal axis bounds 
y: vertical axis bounds
haxis, vaxis: Show horizontal and vertical axes
hgrid, vgrid: Show horizontal and vertical gridlines
"""

Examples


import scisuitplot as plt

plt.layout(2,2)

#All shown
plt.subplot(0,0)
plt.canvas(x=[0,5], y=[0,5])

#Horizontal axis not shown
plt.subplot(0,1)
plt.canvas(x=[0,5], y=[0,5], haxis=False)

#Vertical axis not displayed
plt.subplot(1,0)
plt.canvas(x=[0,5], y=[0,5], vaxis=False)

#Gridlines are not displayed
plt.subplot(1,1)
plt.canvas(x=[0,5], y=[0,5], vgrid=False, hgrid=False)

plt.show()
Different types of canvasses

 

 



histogram

Plots histogram.


def hist(
   data:Iterable, 
   density = False, #by default frequency 
   cumulative = False, 
   breaks:int|Iterable = None, 
   **kwargs):
"""
data:	Numeric data 
density : density histogram if true otherwise frequency.
cumulative : True, cumulative distribution  
breaks : Number of breaks or the break points

## Note
If density=True and cumulative=True, then the histogram is 
normalized so that the cumulative end-value is 1.0
"""

 

Example


import scisuitplot as plt
import scisuit.stats as st

x = st.rnorm(500)
plt.hist(x, fc="255 0 0", lw=2, ec=[0,255,0])

plt.show()
Histogram

 

 



moody

Plots Moody diagram.


def moody(
   Re:Iterable = [1E3, 1E7],
   friction:Iterable = [0.01, 0.09]):
"""
Re: Reynolds number range
friction:  Friction factor range
"""

Examples


import scisuitplot as plt

plt.moody()
plt.show()
Moody Diagram

 

 



psychrometry

Plots psychrometric chart at given pressure, dry-bulb temperature range and relative humidities.


def psychrometry(
   Tdb:Iterable=None, 
   RH:Iterable=None, 
   P:Real=101325.0):
"""
Plots psychromety chart.

Tdb: [min, max], minimum and maximum dry-bulb temperatures (Celcius) 
RH: A list in increasing order containing the requested relative humidity (%) lines 
P: Absolute pressure (Pa)
"""

Example


import scisuitplot as plt

plt.psychrometry()
plt.show()
Psychrometric chart

 

Interactive customizations

Please see the following video.

 

 



QQ Charts

Plots quantile-quantile chart.


def qqnorm(
   data:Iterable, 
   label:str=None, 
   show=True, 
   marker:str|Marker=None,
   **kwargs):
"""
Normal Quantile-quantile chart 
x-axis="Theoretical Quantiles"  
y-axis="Sample Quantiles"

data: Data
show: Whether to show theoretical line or not 
"""


def qqplot(
   x:Iterable, 
   y:Iterable, 
   **kwargs):
"""
x, y: Data
"""

 

Example


import scisuitplot as plt
import scisuit.stats as stat
x=stat.rnorm(100)

#full control on marker
plt.layout(1,2)

plt.subplot(0,0)
plt.qqnorm(x, lw=5, ec=(0, 255,0), 
		marker=plt.Marker(style="s", fc=(255,0,0), lw=2))


#marker with default Pen and Brush properties
plt.subplot(0, 1)
plt.qqnorm(x, lw=3, marker="s")
plt.show()
QQNorm with customized and default properties

 

 



quiver/dirfield

Plots quiver chart and direction field.


def quiver(
   X:np.ndarray, 
   Y:np.ndarray,
   U:np.ndarray, 
   V:np.ndarray,
   scale=None,
   **kwargs)->None:

""""
Plots quiver chart

x, y: (x,y) location, 2D ndarray \n
u, v: length in x and y directions, 2D ndarray \n
scale: if None automatic scaling takes place otherwise xu = x + u*scale is computed
"""	

	

def dirfield(
   x:np.ndarray, 
   y:np.ndarray, 
   slope:np.ndarray):
"""
Plots the direction field for a given function f=dy/dx \n


x, y: 2D numpy array (after using meshgrid) \n
slope: 2D array resulting from evaluation of f=dy/dx, first order ODE
"""

 

Example

Let's visualize the following flow field: V= (u, v) = (0.5+0.8x)i + (1.5-0.8y)j


import scisuitplot as plt
import numpy as np


x = np.arange(-3.0, 3.0, 0.5)
y = np.arange(-1.0, 5.0, 0.5)

X, Y = np.meshgrid(x,y)

U = 0.5 + 0.8*X
V = 1.5 - 0.8*Y

plt.quiver(X,Y, U, V, scale=0.3, ec="#964B00")

plt.show()
Quiver chart

 

 



scatter

Plots scatter chart with/without trendlines.


def scatter(
   x:Iterable,
   y:Iterable,  
   label:str = None, 
   smooth:bool = False, 
   marker:str|Marker = None,
   **kwargs):
"""
x, y:	x- and y-data 
label: Label of the series 
smooth: Uses smoothing algorith to smooth lines (instead of broken)
marker: Marker class to specify marker properties

- To plot lines set `lw` to an int > 0.
- If marker is None and lw is not set, by default markers will be shown.
- Customize line with (lw, ls and edgecolor properties)
- Customize marker with (line properties +  facecolor, hatch)
"""

 

Examples


import scisuitplot as plt
import numpy as np


x = np.arange(0, 6, 0.5)
y = x**2

plt.layout(2,1)

#show line and marker with default pen and brush
plt.subplot(0,0)
plt.scatter(x=x, y=y, lw=3, ls=":", marker="s", markersize=10)

#customize marker properties
plt.subplot(1,0)
plt.scatter(x=x, y=y, marker=plt.Marker(fc="#00FF00"))

plt.show()
Scatter charts