# 3.1 Basic Concepts

### 1.  Figure and Axes&#x20;

For all Matplotlib plots, we start by creating a figure and axes. In their simplest form, a figure and axes can be created as follows:

```
fig = plt.figure()
ax = plt.axes()
```

![ Blank Figure](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MBPOfvLrPMMbV-uBGsx%2F-MBPRUJc_jmSYfZe0oV0%2Fblank%20figure.png?alt=media\&token=b32840b6-c379-4b37-8d15-0983dcd156ab)

For better understanding **axes**, here is an example, we can plot several axes in one figure

```
fig = plt.figure(figsize  = (12,6))   # create a figure and set figure size
ax1= plt.axes()                       # create the first axes
ax2 = plt.axes([0.5, 0.5, 0.3, 0.3])   # create the second axes   
ax3 = plt.axes([0.2,0.2,0.2,0.2])      # create the third axes
```

![ Axes](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MBPOfvLrPMMbV-uBGsx%2F-MBPTJxy_usi97WlYcxY%2Faxes.png?alt=media\&token=36bb36ae-ff44-403c-9e08-209db92425b6)

### 2. Oriented Object&#x20;

Matplotlib graphs your data on [`Figure`](https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure)s (i.e., windows, Jupyter widgets, etc.), each of which can contain one or more [`Axes`](https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes) (i.e., an area where points can be specified in terms of x-y coordinates. It's called **object-oriented.** In other words, you need to create objects.

```
fig, ax = plt.subplots()  # Create a figure containing a single axes
x = np.linspace(0, 10, 100)
ax.plot(x, np.sin(x)) # plot a sine line on the axes
```

![ Simple Oriented Object way](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MBPOfvLrPMMbV-uBGsx%2F-MBPSV2l3EgM_K6Tcm4L%2Foo%20simple%20plot.png?alt=media\&token=7dfcf5ae-a388-4a7c-bce9-8dafeb44fd4b)

{% hint style="warning" %}
According to the last chapter,   could you find the flaw of the chart?
{% endhint %}

### 3.  Pyplot&#x20;

There is a corresponding function in the [`matplotlib.pyplot`](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot) module that performs that plot on the "current" axes, creating that axes (and its parent figure) if they don't exist. So the previous example can be written more shortly as

```
plt.plot([1,2,3,4],[3,2,3,4])  # pyplot way
```

As noted above, there are essentially two ways to use Matplotlib:

* Explicitly create figures and axes, and call methods on them (the "object-oriented (OO) style").
* Rely on `pyplot` to automatically create and manage the figures and axes, and use `pyplot` functions for plotting.

{% hint style="info" %}
If you forget the elements of plot, find it [**here**](https://app.gitbook.com/@ivy-wang/s/crash-visulisation/~/drafts/-MBLFg0lOJc2yNX6jGoq/visualisation-in-python/matplotlib#parts-of-figure)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vecco-insight.gitbook.io/crash-visualization/matplotlib/basic-plot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
