- 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 Stypng
The charts created in python can have further stypng by using some appropriate methods from the pbraries used for charting. In this lesson we will see the implementation of Annotation, legends and chart background. We will continue to use the code from the last chapter and modify it to add these styles to the chart.
Adding Annotations
Many times, we need to annotate the chart by highpghting the specific locations of the chart. In the below example we indicate the sharp change in values in the chart by adding annotations at those points.
import numpy as np from matplotpb import pyplot as plt x = np.arange(0,10) y = x ^ 2 z = x ^ 3 t = x ^ 4 # Labepng the Axes and Title plt.title("Graph Drawing") plt.xlabel("Time") plt.ylabel("Distance") plt.plot(x,y) #Annotate plt.annotate(xy=[2,1], s= Second Entry ) plt.annotate(xy=[4,6], s= Third Entry )
Its output is as follows −
Adding Legends
We sometimes need a chart with multiple pnes being plotted. Use of legend represents the meaning associated with each pne. In the below chart we have 3 pnes with appropriate legends.
import numpy as np from matplotpb import pyplot as plt x = np.arange(0,10) y = x ^ 2 z = x ^ 3 t = x ^ 4 # Labepng the Axes and Title plt.title("Graph Drawing") plt.xlabel("Time") plt.ylabel("Distance") plt.plot(x,y) #Annotate plt.annotate(xy=[2,1], s= Second Entry ) plt.annotate(xy=[4,6], s= Third Entry ) # Adding Legends plt.plot(x,z) plt.plot(x,t) plt.legend([ Race1 , Race2 , Race3 ], loc=4)
Its output is as follows −
Chart presentation Style
We can modify the presentation style of the chart by using different methods from the style package.
import numpy as np from matplotpb import pyplot as plt x = np.arange(0,10) y = x ^ 2 z = x ^ 3 t = x ^ 4 # Labepng the Axes and Title plt.title("Graph Drawing") plt.xlabel("Time") plt.ylabel("Distance") plt.plot(x,y) #Annotate plt.annotate(xy=[2,1], s= Second Entry ) plt.annotate(xy=[4,6], s= Third Entry ) # Adding Legends plt.plot(x,z) plt.plot(x,t) plt.legend([ Race1 , Race2 , Race3 ], loc=4) #Style the background plt.style.use( fast ) plt.plot(x,z)
Its output is as follows −
Advertisements