> For the complete documentation index, see [llms.txt](https://vecco-insight.gitbook.io/crash-visualization/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vecco-insight.gitbook.io/crash-visualization/matplotlib/1.2-line-chart-plot.md).

# 3.2 Line Chart

A **line chart** or **line graph** is a type of chart that displays information as a series of data points called ‘markers’ connected by straight **line segments**. It is a basic type of chart common in many fields.

{% hint style="info" %}
**What to learn:**

* &#x20;Add multiple lines on one figure
* Set  x-label name and y-label &#x20;
* Set  title name
* Set and show legend
  {% endhint %}

```
x = np.linspace(0, 3, 100)
plt.plot(x, x, label='linear')       # Plot  'linear line' on axes.
plt.plot(x, x**2, label='quadratic') # plot 'quadratic line' on the same axes
plt.plot(x, x**3, label='cubic')     #etc
plt.xlabel('this is x label')                      # set the xlabel
plt.ylabel('this is y label')                      # set the ylabel
plt.title('Multi-lines in one figure')             # set the title
plt.legend()                         # show legend
```

<div align="center"><img src="https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MBLKZvCyEVHHjYNBlm4%2F-MBLTzrAmU1psb96T07M%2Fdownload-1.png?alt=media&amp;token=1a69ce44-62fa-40fd-99e5-c69ac2acad63" alt=" Lineplot"></div>

{% hint style="info" %}
**What to learn:**

* change width of a line
* change color of a line
* add markers on a line
* add annotation on line&#x20;
* change location of the legend
  {% endhint %}

```
x = np.arange(1,11)
y1 = np.random.random(10)
y2 = np.random.random(10)

# plot line 1
plt.plot(x, y1,linewidth =5, color = 'c', label = 'line')
# plot line 2
plt.plot(x, y2, marker = 'o',color = 'orange',label = 'line + marker')

# add annotation for line 2
for i in range(len(x)):
    xi = "{:.1f}".format(x[i])
    yi = "{:.1f}".format(y2[i])
    s = str("P(" + str(xi) + ',' + str(yi) + ')' )
    plt.text(x[i] + 0.03, y2[i] + 0.03, s)
    
plt.legend(loc='upper right')    # set legend location
plt.title('Line and line marks') # set title name
plt.show()
```

![ Line and Line marks](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MBORpiaIRH9503k8Egw%2F-MBPMvldUlhmdcTdEfCh%2FLine%20%2B%20line%20mark.png?alt=media\&token=6cc9d94b-4389-4859-bb22-edd949c15311)

{% hint style="info" %}
**What to learn:**

* set different type of lines  ( solid, dashed, dash-dot,  and dotted)
  {% endhint %}

```
plt.plot(x, x + 1, linestyle='-',label = 'solid line')  # solid
plt.plot(x, x + 3, linestyle='--',label = 'dashed line') # dashed
plt.plot(x, x + 5 , linestyle='-.',label = 'dashdot line') # dashdot
plt.plot(x, x + 7, linestyle=':',label = 'dotted')         # dotted
plt.title('Different type of line')                       # title
plt.legend()                                             # show legend
plt.show()
```

![Four types of line](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MBORpiaIRH9503k8Egw%2F-MBPNme8yxrBCs_5K3Ez%2Fdifferent%20type%20of%20line.png?alt=media\&token=d1398304-76bf-4914-859d-7f185325c037)

{% hint style="info" %}
If you find the font size is too small,  you can customize it like this:

```
plt.rcParams.update({'font.size': 20}) # You can change 20 to other values
```

{% endhint %}
