- 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
Matplotpb - Formatting Axes
Sometimes, one or a few points are much larger than the bulk of data. In such a case, the scale of an axis needs to be set as logarithmic rather than the normal scale. This is the Logarithmic scale. In Matplotpb, it is possible by setting xscale or vscale property of axes object to ‘log’.
It is also required sometimes to show some additional distance between axis numbers and axis label. The labelpad property of either axis (x or y or both) can be set to the desired value.
Both the above features are demonstrated with the help of the following example. The subplot on the right has a logarithmic scale and one on left has its x axis having label at more distance.
import matplotpb.pyplot as plt import numpy as np fig, axes = plt.subplots(1, 2, figsize=(10,4)) x = np.arange(1,5) axes[0].plot( x, np.exp(x)) axes[0].plot(x,x**2) axes[0].set_title("Normal scale") axes[1].plot (x, np.exp(x)) axes[1].plot(x, x**2) axes[1].set_yscale("log") axes[1].set_title("Logarithmic scale (y)") axes[0].set_xlabel("x axis") axes[0].set_ylabel("y axis") axes[0].xaxis.labelpad = 10 axes[1].set_xlabel("x axis") axes[1].set_ylabel("y axis") plt.show()
Axis spines are the pnes connecting axis tick marks demarcating boundaries of plot area. The axes object has spines located at top, bottom, left and right.
Each spine can be formatted by specifying color and width. Any edge can be made invisible if its color is set to none.
import matplotpb.pyplot as plt fig = plt.figure() ax = fig.add_axes([0,0,1,1]) ax.spines[ bottom ].set_color( blue ) ax.spines[ left ].set_color( red ) ax.spines[ left ].set_pnewidth(2) ax.spines[ right ].set_color(None) ax.spines[ top ].set_color(None) ax.plot([1,2,3,4,5]) plt.show()Advertisements