Customization using Matplotlib in Python.

1. What is Matplotlib
Matplotlib is a popular data visualization library in Python widely used for creating static, interactive, and animated visualizations in Python. We can represent our data in many interactive ways like Graphs, Histograms, Pie Char…


This content originally appeared on DEV Community and was authored by Keshav Jindal

1. What is Matplotlib
Matplotlib is a popular data visualization library in Python widely used for creating static, interactive, and animated visualizations in Python. We can represent our data in many interactive ways like Graphs, Histograms, Pie Chart, etc.

2. Why Matplotlib
It provides a wide range of customization options to make your graphs more informative and visually appealing. Here are some of the customization options available in Matplotlib:

  • Adding markers
  • Changing kind of graph
  • Adding labels and titles
  • Adding legends

3. Using markers in graphs
Markers in Matplotlib are used to represent data points on a plot with a symbol, such as a circle, square, or triangle. We can perform various function and customizations using keyword *marker * like:

  • Changing the marker size
  • Changing the marker color
  • Changing the marker edge color and width

Syntax

import matplotlib.pyplot as plt
import pandas as pd

ypoints = [10,20,34,40,15]

plt.plot(ypoints, marker = 'o', markeredgecolor='black', markersize=7, markerfacecolor='red')
plt.show()

Output

Image description

4. Different kind to represent our data
We can represent our data in many interactive forms like:
Pie charts, Histograms, BarCharts, etc. using a keyword kind.
Note
Kind of graph is written as a string.

Syntax

import matplotlib.pyplot as plt
import pandas as pd

data = {'x': [1, 2, 3, 4, 5], 'y': [2, 4, 6, 8, 10]}
df = pd.DataFrame(data)
graph = df.plot(kind="bar")
plt.show(graph)

Output:

Image description

5. Labels and titles
Labels and titles are most important components of a Matplotlib plot, as they provide information about the data being visualized. They make the plot easier to understand. We can add labels both on x and y axis while title provides the plot to a name which becomes more informative.
Syntax

import matplotlib.pyplot as plt
import pandas as pd

data = {'x': [1, 2, 3, 4, 5], 'y': [2, 4, 6, 8, 10]}
df = pd.DataFrame(data)
graph = df.plot(kind="bar")
plt.title("Monthly Sales")
plt.xlabel("Years")
plt.ylabel("Sales")
plt.show(graph)

Output

Image description

6. Customization using Legend
Legend is used to identify and distinguish between different plots in a figure. We can change the color of multiple bars which makes our plot more interactive and easier to understand.
Syntax

import matplotlib.pyplot as plt
import pandas as pd

data = {'x': [1, 2, 3, 4, 9], 'y': [2, 5, 6, 8, 10]}
df = pd.DataFrame(data)
graph = df.plot(kind="bar")
plt.legend(["blue","orange"])
plt.show(graph)

Output

Image description


This content originally appeared on DEV Community and was authored by Keshav Jindal


Print Share Comment Cite Upload Translate Updates
APA

Keshav Jindal | Sciencx (2023-03-07T18:17:00+00:00) Customization using Matplotlib in Python.. Retrieved from https://www.scien.cx/2023/03/07/customization-using-matplotlib-in-python/

MLA
" » Customization using Matplotlib in Python.." Keshav Jindal | Sciencx - Tuesday March 7, 2023, https://www.scien.cx/2023/03/07/customization-using-matplotlib-in-python/
HARVARD
Keshav Jindal | Sciencx Tuesday March 7, 2023 » Customization using Matplotlib in Python.., viewed ,<https://www.scien.cx/2023/03/07/customization-using-matplotlib-in-python/>
VANCOUVER
Keshav Jindal | Sciencx - » Customization using Matplotlib in Python.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/03/07/customization-using-matplotlib-in-python/
CHICAGO
" » Customization using Matplotlib in Python.." Keshav Jindal | Sciencx - Accessed . https://www.scien.cx/2023/03/07/customization-using-matplotlib-in-python/
IEEE
" » Customization using Matplotlib in Python.." Keshav Jindal | Sciencx [Online]. Available: https://www.scien.cx/2023/03/07/customization-using-matplotlib-in-python/. [Accessed: ]
rf:citation
» Customization using Matplotlib in Python. | Keshav Jindal | Sciencx | https://www.scien.cx/2023/03/07/customization-using-matplotlib-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.