0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

How to use twinx()

Posted at

How to use twinx()

import modules

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('bmh')

prepare dummy datas

X = np.linspace(1, 10, 100)

y1 = X * 2.0
y2 = -4.0 * X + 25.0 

prepare plotting twinx()

fig, ax = plt.subplots(1, 1)
ax2 = ax.twinx()

plot left bar

ax.plot(X, y1)
ax.set_ylim(0, 30)
ax.set_ylabel('y1 for left_bar [Kg]')

plot right bar

ax2.plot(X, y2 ,ls=':', lw=0.5, c='r', alpha=0.3)
ax2.set_ylim(0, 30)
ax2.set_ylabel('y2 for left_bar [m]')

show

ax.set_title('twin_X')
fig
plt.show()

samaple01.jpg

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?