Skip to content

Instantly share code, notes, and snippets.

@seafooler
Created November 12, 2019 13:16
Show Gist options
  • Save seafooler/f7e421e633f0dcb4d0d2b3706dd8ab40 to your computer and use it in GitHub Desktop.
Save seafooler/f7e421e633f0dcb4d0d2b3706dd8ab40 to your computer and use it in GitHub Desktop.
Example for drawing multiple lines with two y axises in Python
import matplotlib.pyplot as plt
xticks = ['86','87','88','89','90','91','92','93','94','95']
num_n = [1827,3194,3659,2331,214,264,3407,1961,116,1038]
num_m = [3053,6588,5766,3729,368,1621,5722,3205,152,1879]
time_p = [1056,2908.1,1910.2,1188.1,78,4284.6,2271.4,874.46,38.3645,1101.2]
time_q = [13.012,73.2918,27.5084,14.64,2.1909,4.901,24.13991,13.5521,0.7378,8.5]
fig, ax1 = plt.subplots(figsize=(10, 6))
ax1.plot(xticks, num_n, 'H--r', label="num_n")
ax1.plot(xticks, num_m, 'o--b', label="num_m")
ax1.set_yscale("log")
ax1.set_ylim(1e-1, 1e4)
ax1.set_ylabel('Number', fontsize = 'large')
ax1.set_xlabel('BBBBBBB',fontsize = 'large')
ax1.legend(loc=0, fontsize=10)
ax2 = ax1.twinx()
ax2.plot(xticks, time_p, '*-g', label="time_p")
ax2.plot(xticks, time_q, 's-c', label="time_q")
ax2.set_yscale("log")
ax2.set_ylim(1e-1, 1e4)
ax2.set_ylabel('Time (ms)', fontsize = 'large')
plt.tight_layout()
ax2.legend(loc=3, fontsize=10)
plt.savefig("test.eps")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment