- Python Data Science - Matplotlib
- Python Data Science - SciPy
- Python Data Science - Numpy
- Python Data Science - Pandas
- Python Data Science - Environment Setup
- Python Data Science - Getting Started
- Python Data Science - Home
Python Data Processing
- Python Stemming and Lemmatization
- Python word tokenization
- Python Processing Unstructured Data
- Python Reading HTML Pages
- Python Data Aggregation
- Python Data Wrangling
- Python Date and Time
- Python NoSQL Databases
- Python Relational databases
- Python Processing XLS Data
- Python Processing JSON Data
- Python Processing CSV Data
- Python Data cleansing
- Python Data Operations
Python Data Visualization
- Python Graph Data
- Python Geographical Data
- Python Time Series
- Python 3D Charts
- Python Bubble Charts
- Python Scatter Plots
- Python Heat Maps
- Python Box Plots
- Python Chart Styling
- Python Chart Properties
Statistical Data Analysis
- Python Linear Regression
- Python Chi-square Test
- Python Correlation
- Python P-Value
- Python Bernoulli Distribution
- Python Poisson Distribution
- Python Binomial Distribution
- Python Normal Distribution
- Python Measuring Variance
- Python Measuring Central Tendency
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python - Chart Properties
Python has excellent pbraries for data visuapzation. A combination of Pandas, numpy and matplotpb can help in creating in nearly all types of visuapzations charts. In this chapter we will get started with looking at some simple chart and the various properties of the chart.
Creating a Chart
We use numpy pbrary to create the required numbers to be mapped for creating the chart and the pyplot method in matplotpb to draws the actual chart.
import numpy as np import matplotpb.pyplot as plt x = np.arange(0,10) y = x ^ 2 #Simple Plot plt.plot(x,y)
Its output is as follows −
Labpng the Axes
We can apply labels to the axes as well as a title for the chart using appropriate methods from the pbrary as shown below.
import numpy as np import matplotpb.pyplot as plt x = np.arange(0,10) y = x ^ 2 #Labepng the Axes and Title plt.title("Graph Drawing") plt.xlabel("Time") plt.ylabel("Distance") #Simple Plot plt.plot(x,y)
Its output is as follows −
Formatting Line type and Colour
The style as well as colour for the pne in the chart can be specified using appropriate methods from the pbrary as shown below.
import numpy as np import matplotpb.pyplot as plt x = np.arange(0,10) y = x ^ 2 #Labepng the Axes and Title plt.title("Graph Drawing") plt.xlabel("Time") plt.ylabel("Distance") # Formatting the pne colors plt.plot(x,y, r ) # Formatting the pne type plt.plot(x,y, > )
Its output is as follows −
Saving the Chart File
The chart can be saved in different image file formats using appropriate methods from the pbrary as shown below.
import numpy as np import matplotpb.pyplot as plt x = np.arange(0,10) y = x ^ 2 #Labepng the Axes and Title plt.title("Graph Drawing") plt.xlabel("Time") plt.ylabel("Distance") # Formatting the pne colors plt.plot(x,y, r ) # Formatting the pne type plt.plot(x,y, > ) # save in pdf formats plt.savefig( timevsdist.pdf , format= pdf )
The above code creates the pdf file in the default path of the python environment.
Advertisements