Matplotlib Tutorial
Matplotlib Useful Resources
Selected Reading
- Matplotlib - Transforms
- Matplotlib - Working with Images
- Mathematical Expressions
- Matplotlib - Working With Text
- Matplotlib - 3D Surface plot
- Matplotlib - 3D Wireframe plot
- Matplotlib - 3D Contour Plot
- Three-dimensional Plotting
- Matplotlib - Violin Plot
- Matplotlib - Box Plot
- Matplotlib - Quiver Plot
- Matplotlib - Contour Plot
- Matplotlib - Scatter Plot
- Matplotlib - Pie Chart
- Matplotlib - Histogram
- Matplotlib - Bar Plot
- Matplotlib - Twin Axes
- Setting Ticks and Tick Labels
- Matplotlib - Setting Limits
- Matplotlib - Formatting Axes
- Matplotlib - Grids
- Matplotlib - Subplot2grid() Function
- Matplotlib - Subplots() Function
- Matplotlib - Multiplots
- Matplotlib - Axes Class
- Matplotlib - Figure Class
- Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Simple Plot
- Matplotlib - Pyplot API
- Matplotlib - Jupyter Notebook
- Matplotlib - Anaconda distribution
- Matplotlib - Environment Setup
- Matplotlib - Introduction
- Matplotlib - Home
Matplotlib Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Matplotlib - Twin Axes
Matplotpb - Twin Axes
It is considered useful to have dual x or y axes in a figure. Moreso, when plotting curves with different units together. Matplotpb supports this with the twinxand twiny functions.
In the following example, the plot has dual y axes, one showing exp(x) and the other showing log(x) −
import matplotpb.pyplot as plt import numpy as np fig = plt.figure() a1 = fig.add_axes([0,0,1,1]) x = np.arange(1,11) a1.plot(x,np.exp(x)) a1.set_ylabel( exp ) a2 = a1.twinx() a2.plot(x, np.log(x), ro- ) a2.set_ylabel( log ) fig.legend(labels = ( exp , log ),loc= upper left ) plt.show()Advertisements