Functions to configure plotting.
def figure():
"""
Start a new plot window
"""
Adds the chart to the list of plot windows that will be shown when plt.show is called.
//Add current plot window to the list
PlotWndList.push_back(CurPlotWnd);
import scisuitplot as plt
plt.scatter(x=[1,2,3], y=[1,4,9])
plt.figure()
"""
As of this point the rest of the
code is applied to new plot window
"""
plt.scatter(x=[1,2,3], y=[1,8,27])
plt.show()
You should see two separate plot windows.
Please also see subplot.
def layout(
nrows:numbers.Integral,
ncols:numbers.Integral)->None:
"""
Partitions the current chart window into nrows and ncols
(similar to a matrix with nrows and ncols)
nrows: number of rows
ncols: number of columns
"""
import scisuitplot as plt
plt.layout(nrows=2, ncols=2)
Adds legend to the chart.
def legend(
nrows:int|None = None,
ncols:int|None = None)->None:
import scisuitplot as plt
import numpy as np
x = np.arange(0, 6, 0.5)
plt.scatter(x=x, y=x**2, lw=3, ls=":", marker="s")
plt.scatter(x=x, y=x, lw=3, ls=":", marker="s")
plt.scatter(x=x, y=2*x, lw=3, ls=":", marker="x", label = "2x")
plt.legend(2,2)
plt.show()
def set_xticks(
ticks:Iterable,
labels=None,
align="center",
pos="bottom")->None:
"""
Sets the x-ticks and optionally labels
align: "center", "left"
pos: "top", "bottom"
"""
def set_yticks(
ticks:Iterable,
labels=None,
align="center",
pos="left")->None:
"""
Sets the x-ticks and optionally labels.
align: "center", "top", "bottom"
pos: "left", "right"
"""
def set_xposition(position:numbers.Real)->None:
"""
Sets x-axis position
position: A valid position within limits of y-axis
"""
def set_yposition(position:numbers.Real)->None:
"""
Sets y-axis position
position: A valid position within limits of x-axis
"""
Following demonstrates the ylabel; however, similar rationale applies to xlabel.
import scisuitplot as plt
plt.layout(2,1)
plt.subplot(0,0)
plt.canvas(x=[-5,5], y=[-5,5])
plt.subplot(1,0)
plt.canvas(x=[-5,5], y=[-5,5])
plt.set_xposition(position=0)
plt.set_yposition(position=0)
plt.show()
def show(shared = False):
"""
Starts main loop and shows the chart(s)
shared: if there is any other application using a main loop
"""
Processes the PlotWndList data structure. Therefore, must be called at the end.
//Show all plot windows
for (auto Wnd : PlotWndList)
Wnd->Show();
Please also see layout.
def subplot(
row:numbers.Integral,
col:numbers.Integral,
nrows:numbers.Integral = 1,
ncols:numbers.Integral = 1)->None:
"""
Must be called after the window is partitioned (by layout)
to select a cell from the partition.
row: row position of the cell (must be less than partition's number of rows),
col: column position of the cell (must be less than partition's number of columns),
nrows: number of rows the cell should span
ncols: number of columns the cell should span
"""
import scisuitplot as plt
plt.layout(nrows=2, ncols=2)
plt.subplot(row=0, col=0, nrows = 1, ncols = 2)
def title(label:str):
"""
Creates chart title
"""
import scisuitplot as plt
import numpy as np
x=np.arange(0,4)
#plt.title("Quadratic function") -> WONT WORK
plt.scatter(x=x, y=x**2)
plt.title("Quadratic function")
plt.show()
Following are valid:
def xlabel(label:str):
"""Create x-axis label"""
def ylabel(label:str):
"""Create y-axis label"""
Following demonstrates the ylabel; however, similar rationale applies to xlabel.
import scisuitplot as plt
import numpy as np
x=np.arange(0,4)
#plt.ylabel("y-values") -> WONT WORK
plt.scatter(x=x, y=x**2)
plt.ylabel("y-values")
plt.show()
Following are valid:
def xlim(
min:numbers.Real|None = None,
max:numbers.Real|None = None)->tuple|None:
"""
Sets or gets the x-limits of the current chart
"""
def ylim(
min:numbers.Real|None = None,
max:numbers.Real|None = None)->tuple|None:
"""
Sets or gets the y-limits of the current chart
"""
import scisuitplot as plt
plt.layout(2,1)
#All shown
plt.subplot(0,0)
plt.canvas(x=[0,5], y=[0,5])
print(plt.xlim())
#(0.0, 5.0)
plt.subplot(1,0)
#initial bounds
plt.canvas(x=[0,5], y=[0,5])
#bounds changed
plt.xlim(0, 3)
plt.ylim(0, 3)
plt.show()
By default the axes scales are "linear".
def xscale(value:str)->None:
"""
Sets x-axis scale
value: "linear", "log"
"""
def yscale(value:str)->None:
"""
Sets y-axis scale
value: "linear", "log"
"""