2-axis plot with Matplotlib

Return to list

image.png

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.size']=15

np.random.seed(1)
plt.figure(figsize=(12,3.5))

ax0 = plt.subplot(121)
ax1 = ax0.twinx()
ax2 = plt.subplot(122)
ax3 = ax2.twinx()

ax1.get_shared_y_axes().join(ax1, ax3)

ax0.plot(np.random.rand(1) * np.random.rand(10),'r')
ax0.grid()
ax1.plot(10*np.random.rand(1) * np.random.rand(10),'b')

ln2 = ax2.plot(3*np.random.rand(1) * np.random.rand(10),'r',label='red')
ax2.grid()
ln3 = ax3.plot(10*np.random.rand(1) * np.random.rand(10),'b',label='blue')

# legend
lns = ln2 + ln3
labs = [l.get_label() for l in lns]
ax3.legend(lns, labs, bbox_to_anchor=(1.1, 1), loc='upper left', borderaxespad=0, )

plt.show()

Recommended Posts

2-axis plot with Matplotlib
3D plot with matplotlib
Stackable bar plot with matplotlib
Create plot animation with Python + Matplotlib
Continuously color with matplotlib scatter plot
Lognormal probability plot with Python, matplotlib
Animation with matplotlib
Japanese with matplotlib
Animation with matplotlib
Histogram with matplotlib
Animate with matplotlib
Draw hierarchical axis labels with matplotlib + pandas
[Python] limit axis of 3D graph with Matplotlib
Plot ROC Curve for Binary Classification with Matplotlib
Heatmap with Python + matplotlib
Band graph with matplotlib
2D plot in matplotlib
Learn with Cheminformatics Matplotlib
Real-time drawing with matplotlib
Various colorbars with Matplotlib
Create 3D scatter plot with SciPy + matplotlib (Python)
matplotlib: Replace the axis itself with another one.
Time series plot / Matplotlib
Adjust axes with matplotlib
[Python] How to draw a scatter plot with Matplotlib
Candle chart plot with plotly
Graph Excel data with matplotlib (1)
Try using matplotlib with PyCharm
Graph drawing method with matplotlib
Graph Excel data with matplotlib (2)
3D scatter plot with PyQtGraph
Gradient color selection with matplotlib
Animate multiple graphs with matplotlib
Reformat the timeline of the pandas time series plot with matplotlib
A python graphing manual with Matplotlib.
Inference & result display with Tensorflow + matplotlib
Japaneseize Matplotlib with Alpine using Docker
[Python] font family and font with matplotlib
Draw Japanese with matplotlib on Ubuntu
Draw a loose graph with matplotlib
Versatile data plotting with pandas + matplotlib
Heatmap with Dendrogram in Python + matplotlib
Easy Japanese font setting with matplotlib
Easy to draw graphs with matplotlib
Cases using pandas plot, cases using (pure) matplotlib plot
Draw Lyapunov Fractal with Python, matplotlib
When matplotlib doesn't work with python2.7
Easy animation with matplotlib (mp4, gif)
Write a stacked histogram with matplotlib
Implement "Data Visualization Design # 2" with matplotlib
Plot black and white graphs suitable for papers with matplotlib or pylab
Plot CSV of time series data with unixtime value in Python (matplotlib)
Plot multiple maps and data at the same time with Python's matplotlib
How to title multiple figures with matplotlib
[Python] Set the graph range with matplotlib
Adjust the spacing between figures with Matplotlib
Plot the Nikkei Stock Average with pandas
Align the size of the colorbar with matplotlib
Try drawing a normal distribution with matplotlib
Make a partially zoomed figure with matplotlib
Write SVG graphs with matplotlib on heroku