Eastsun
Eastsun

Reputation: 18869

How to display yaxis on both side using matplotlib 0.99?

I want to display yaxis on both side. In matplotlib 1.2, I can use following code:

ax.tick_params(labelright = True)

However, there is no method tick_params for Axes in matplotlib 0.99. Is there any simple way to do this in 0.99? Tks

EDIT I got this solution followed by @Brian Cain's

ax2 = ax1.twinx()
ax2.set_yticks(ax1.get_yticks())
ax2.set_yticklabels([t.get_text() for t in ax1.get_yticklabels()])

Upvotes: 3

Views: 3011

Answers (1)

Brian Cain
Brian Cain

Reputation: 14619

Here is an example from matplotlib docs with differing scales on each Y axis. You could use the same scale if you preferred.

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(111)
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax1.plot(t, s1, 'b-')
ax1.set_xlabel('time (s)')
# Make the y-axis label and tick labels match the line color.
ax1.set_ylabel('exp', color='b')
for tl in ax1.get_yticklabels():
    tl.set_color('b')


ax2 = ax1.twinx()
s2 = np.sin(2*np.pi*t)
ax2.plot(t, s2, 'r.')
ax2.set_ylabel('sin', color='r')
for tl in ax2.get_yticklabels():
    tl.set_color('r')
plt.show()

Resulting image

Upvotes: 4

Related Questions