# MatplotLib - Customizing graphs

1) *change the color of the line*

<mark>x = [1, 2, 3]</mark>

<mark>y = [3, 4, 5]</mark>

/ run either one of the below lines to see the changes

<mark>plt.plot(x, y, "b") -&gt; blue color line</mark>

<mark>plt.plot(x, y, "r") -&gt; red color line</mark>

<mark>plt.plot(x, y, color = "black") -&gt; another option</mark>

<mark>plt.show()</mark>

2) *changing the pattern of the line*

<mark>x = [1, 2, 3]</mark>

<mark>y = [3, 4, 5]</mark>

/ run either one of the below lines to see the changes

/ Here, the 1st letter is for color and the 2nd letter and onwards will be used for pattern types.

<mark>plt.plot(x, y, "ro") -&gt; dot-like line</mark>

<mark>plt.plot(x, y, "r--") -&gt; dashed line</mark>

<mark>plt.plot(x, y, color = "black", marker = "--") -&gt; another option</mark>

<mark>plt.show()</mark>

Note: Check the documentation for more color options and pattern types

3) *changing the line width*

<mark>x = [1, 2, 3]</mark>

<mark>y = [3, 4, 5]</mark>

/ run either one of the below lines to see the output

<mark>plt.plot(x, y, color = "black", linewidth = 0.5) -&gt; thin line</mark>

<mark>plt.plot(x, y, color = "black", linewidth = 5) -&gt; thicker line</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

4) *adding x and y label*

<mark>x = [1, 2, 3]</mark>

<mark>y = [3, 4, 5]</mark>

<mark>plt.xlabel("x")</mark>

<mark>plt.ylabel("y")</mark>

<mark>plt.plot(x, y, color = "black")</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

Note: Make sure the values passed in xlabel() and ylabel() be inside " "

5) *adding the title*

<mark>x = [1, 2, 3]</mark>

<mark>y = [3, 4, 5]</mark>

<mark>plt.title("Demo")</mark>

<mark>plt.plot(x, y, color = "black")</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

6) *adding names to lines and legends*

/ Adds a small description about the line the corner of the graph

<mark>a = [1, 2, 3]</mark>

<mark>a_sqre = [1, 4, 9]</mark>

<mark>a_cube = [1, 8, 27]</mark>

/ only adding label attribute won't do anything, make sure to call the legend()

<mark>plt.plot(a, a_sqre, color = "black", label = "a^2")</mark>

<mark>plt.plot(a, a_cube, color = "red", label = "a^3")</mark>

<mark>plt.legend()</mark>

<mark>plt.plot()</mark>

7) *changing the axis values*

<mark>x = [1, 2, 3]</mark>

<mark>y = [3, 4, 5]</mark>

<mark>plt.axis([0, 5, 3, 5]) -&gt; pass a list in form of [x_axis_start, x_axis_end, y_axis_start, y_axis_end]</mark>

<mark>plt.plot(x, y, color = "black")</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

8) *For a better understanding*

<mark>x = [1, 2, 3]</mark>

<mark>y = [3, 4, 5]</mark>

<mark>plt.plot(x, y, color = "black")</mark>

<mark>plt.grid() -&gt; gives a grid-like structure in the background similar to the graph paper</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>

9) *Adding some details at a particular point*

<mark>x = [1, 2, 3]</mark>

<mark>y = [3, 4, 5]</mark>

<mark>plt.plot(x, y, color = "black")</mark>

/ font size is optional argument

/ syntax plt.text(x\_point, y\_point, "any text you want to add")

<mark>plt.text(1, 3, "Lowest value", fontsize = 10)</mark>

<mark>plt.text(2, 4, "Mid value", fontsize = 10)</mark>

<mark>plt.text(3, 5, "Highest value", fontsize = 10)</mark>

[<mark>plt.show</mark>](http://plt.show)<mark>()</mark>
