- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to generate statistical graphs using Python?
Python has an amazing graph plotting library called matplotlib. It is the most popular graphing and data visualization module for Python. You can start plotting graphs using 3 lines! For example,
from matplotlib import pyplot as plt # Plot to canvas plt.plot([1,2,3],[4,5,1]) #Showing what we plotted plt.show()
This will create a simple graph with coordinates (1,4), (2,5) and (3,1). You can Assign labels to the axes using the xlabel and ylabel functions. For example,
plt.ylabel('Y axis') plt.xlabel('X axis')
And also provide a title using the title function −
plt.title('My Graph')
Remember to call these before the show() call as it will render these only if called before show. You can also style these graphs by providing arguments like linewidth=2 to the plt.plot function. You can also use the legend() function to create a legend:
plt.legend()
There are many types of charts like bar graph, scatterplots, pie chart, etc. available. You can learn more about these on https://pythonprogramming.net/matplotlib-python-3-basics-tutorial/