> For the complete documentation index, see [llms.txt](https://jona-projects.gitbook.io/kiwicalc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jona-projects.gitbook.io/kiwicalc/visualization/plotting-methods.md).

# Plotting methods

### Plotting Methods

The module contains a set of plotting functions with [matplotlib](https://matplotlib.org/). These methods are extremely easy to use - you don't have to engage with the relatively sophisticated technical details involving matplotlib's interface. Although many classes in KiwiCalc provide plotting abilities, you don't have to learn any of them to use these methods.

#### `scatter_dots()`

You can scatter dots in 2D via the `scatter_dots()` method. Here is the signature of the method:

```python
def scatter_dots(x_values, y_values, title: str = "", ymin:float=-10, ymax:float=10,show_axis=True,
     show=True):
```

For example:

```python
scatter_dots([1,2,3,4],[2,4,6,8], title="Matplotlib is awesome")            
```

Output:

#### `scatter_dots_3d()`

You can scatter dots in 3D via the `scatter_dots_3d()` method. Here is the signature of the method:

```python
def scatter_dots_3d(x_values, y_values, z_values, title: str = "", fig=None,
      ax=None, show_axis=True, show=True):                
```

For example:

```python
scatter_dots_3d([4, 2, 8, -5, 3, 8, 9, -6, 1], [1, 9, -2, 3, 4, 5, 1, 6, 7], [1, -1, 3, 4, 8, 1, 4, 2, 6])                
```

Output:

#### `plot_function()`

You can plot functions with only variable on a 2D axis system via the `plot_function()` method. Here is the signature of the method:

```python
def plot_function(func: Union[Callable, str], start: float = -10, stop: float = 10,
                 step: float = 0.01, ymin: float = -10, ymax: float = 10, title=None, show_axis=True, show=True,
                 fig=None, ax=None, formatText=True, values=None):              
```

Parameters

* `func`- A function to plot. We offer a variety of ways to enter this function. You can enter any matching callable object, such as lambda expressions and Function objects. You can even enter a string that represents the function. This is as simple as it gets...
* `start`- Where to start plotting
* `stop`- Where to stop plotting
* `step`- Interval between each \`x\`
* `ymin`- Smallest \`y\` in the scope
* `ymax`- Biggest \`y\` in the scope
* `title`- The title of the graph
* `show_axis`- Whether to show the \`x\` and \`y\` axis or not ( `True` / `False`)
* `show`- Whether to show the graph or not ( `True` / `False`)
* `fig`- An existing matplotlib figure to plot in. In order to use this parameter, you must also the ax parameter.
* `ax`- An existing axis in matplotlib. In order to use this parameter, you must also the fig parameter.
* `formatText`- An experimental feature: whether to try formatting the text into latex or not. Currently it's slow and therefore the default is `False`. However, in later versions, this might be more advanced.
* `values`- Instead of specifying a range via the `start`, `stop` and `step` parameters, you can specify the \`x\` values yourself.

For instance:

```python
plot_function("f(x) = x^2")
                    
```

Output:

```python
plot_function(Function("f(x) = sin(x)"))
                    
```

```python
plot_function(lambda x: 2*x)
                    
```

#### `plot_function_3d()`

You can plot functions with 2 variables on a 3D axis system via the `plot_function_3d()` method. Here is the signature of the method:

```python
def plot_function_3d(given_function:"Union[Callable, str]", start: float = -3, stop: float = 3, step: float = 0.1, xlabel: str = "X Values",
      ylabel: str = "Y Values", zlabel: str = "Z Values"):
                    
```

For instance:

```python
plot_function_3d("f(x,y) = sin(x)*cos(y)")        
```

Output:

<figure><img src="/files/jqG2VPbQSByNaG2h48pZ" alt=""><figcaption></figcaption></figure>

#### `scatter_function()`

You can scatter functions with only 1 variables on a 2D axis system via the `scatter_function()` method. Here is the signature of the method:

```python
def scatter_function(func: Union[Callable, str], start: float = -10, stop: float = 10,
        step: float = 0.5, ymin: float = -10, ymax: float = 10, title="", show_axis=True, show=True):
                    
```

For example:

```python
scatter_function("f(x) = sin(x)")      
```

Output:

<figure><img src="/files/HmZe6qF5zrZXdXUQAf4I" alt=""><figcaption></figcaption></figure>

```python
scatter_function(lambda x:x**2)           
```

<figure><img src="/files/ibUQT7RyjjHSZUXocIUQ" alt=""><figcaption></figcaption></figure>

```python
scatter_function(Function("f(x) = 2x"))                   
```

#### `scatter_function_3d()`

You can scatter functions with 2 variables on a 3D axis system via the `scatter_function_3d()` method. Here is the signature of the method:

```python
def scatter_function_3d(func: "Union[Function, str]", start: float = -10, stop: float = 10,
     step: float = 0.5, title=None, show=True):
                    
```

For example:

```python
scatter_function_3d("f(x,y) = x + y")
```

```python
import math
scatter_function_3d(lambda x, y: math.sin(x)*math.cos(y))
                    
```

<pre class="language-python"><code class="lang-python"><strong>scatter_function_3d(Function("f(x,y) = xy"), title="Hi there!")
</strong>                    
</code></pre>

#### `plot_functions()`

You can plot several functions with only 1 variable on a 2D axis system via the `plot_functions()` method. Here is the signature of the method:

```python
def plot_functions(functions, start: float = -10, stop: float = 10, step: float = 0.01, ymin: float = -10,
     ymax: float = 10, text: str = None,
     show_axis: bool = True, show: bool = True):     
```

For example:

```python
plot_functions(["f(x) = 2x", "f(x) = x^2", "f(x) = sin(x)"])          
```

#### `plot_functions_3d()`

You can plot several functions with 2 variables on a 3D axis system via the `plot_functions_3d()` method. Here is the signature of the method:

```python
def plot_functions_3d(functions: "Iterable[Union[Callable, str, IExpression]]", start: float = -5, stop: float = 5,
     step: float = 0.1,
     xlabel: str = "X Values",
     ylabel: str = "Y Values", zlabel: str = "Z Values"):
                    
```

For instance:

```python
plot_functions_3d(["f(x,y) = sin(x)*cos(y)", "f(x,y) = sin(x)*ln(y)"])             
```

Output:

<figure><img src="/files/9ArEqdmXClqDNwxAzNZb" alt=""><figcaption></figcaption></figure>

If the plot is too laggy, try increasing the `step` parameter.

#### `plot_multiple()`

You can plot several functions on different figures via the `plot_multiple()` method. Here is the signature of the method:

```python
 def plot_multiple(funcs, shape: Tuple[int, int] = None, start: float = -10, stop: float = 10,
                  step: float = 0.01, ymin: float = -10, ymax: float = 10, title=None, show_axis=True, show=True,
                  values=None):           
```

The method accepts parameters:

* `funcs`- a collection of functions - you can enter strings, lambda expressions, `Function` objects, algebraic expressions, etc.
* `shape(optional)` A tuple of two integers that represents the shape of the figures - for instance, a grid of 3x3 figures. If not specified, the best fitting shape will be chosen automatically.
* `start(optional)`Where to start plotting from - `float`. Default is `-10`
* `stop(optional)`Where to end plotting - `float`. The default is `10`
* `step(optional)`- The distance between each x value in the plotting range, of type `float`. The default is 0.01. Smaller steps result in higher accuracy but it makes the plotting process much slower and often cause lags.
* `ymin(optional)`- the smallest \`y\` value that will be visible in the scope of the plot, of type `float`. The default is -10.
* `ymax(optional)`- the highest \`y\` value that will be visible in the scope, of type `float`. The default is 10.
* `title(optional)`- The title of the plot.
* `show_axis(optional)`- Whether to show the axis or not in the plot. The default is `True`.
* `show(optional)`- Whether to show the plot. The default is True.
* `values(optional)`- Default is `None`. If this parameter is not None, its value will be used as the range of x values to plot in instead of the `start`, `stop`, and `step` parameters.

For instance:

```python
plot_multiple(["f(x) = 4x", "f(x) = x^2", "f(x) = x^3", "f(x)= 8", "f(x)=ln(x)", "f(x)=e^x", "f(x)=|x|", "f(x)=sin(x)", "f(x)=cos(x)"])              
```

Output:

<figure><img src="/files/ZX7DluTvRfcDNA1qEAsR" alt=""><figcaption><p>Plotting 9 functions - in a single line of code. C'mon. We know you're impressed.</p></figcaption></figure>

#### `plot_complex()`

You can plot a complex number or several complex numbers via the `plot_complex()` method. Here is the signature of the method:

```python
def plot_complex(*numbers: complex, title:str="", show=True):              
```

Parameters

* `*numbers` - complex numbers to plot
* `title` - specify a title for the plot
* `show` - whether to show the plot or not ( `True` / `False`)

For example:

```python
plot_complex(complex(5, 4), complex(3, -2))              
```

Output:

<figure><img src="/files/D6O2mNPa5CpUZKFowWtf" alt=""><figcaption></figcaption></figure>
