Created
November 7, 2019 09:54
-
-
Save seafooler/a006fc0bf2095696bc67b4b1be20e36f to your computer and use it in GitHub Desktop.
Example for drawing a bar and a line in the same figure in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
xticks = ['15-1','15-2','15-3','15-4','16-1','16-2','16-3','16-4', | |
'17-1','17-2','17-3','17-4','18-1','18-2','18-3','18-4','19-1','19-2','19-3'] | |
cnt = np.array([17.17646221,19.43652252,30.54252321,32.78014989,34.46738787,37.55476953,40.99359145,42.65602493, | |
45.62631487,50.40547517,51.19912708,55.64568829,57.58204446,51.35193284,49.39556185,50.08214678, | |
50.84948824,55.20547267,60.22801956]) | |
size = np.array([5.735962982,6.630246013,9.499133204,10.29255457,11.19376834,12.47500742,14.02777201,15.28399689, | |
16.944369,19.15263185,22.12279345,29.85357858,31.09525989,27.87855024,27.10313029,27.78113192, | |
28.45668532,31.1445823,34.29272631]) | |
fig, ax1 = plt.subplots(figsize=(10, 6)) | |
ax1.bar(xticks, cnt) | |
ax1.set_xlabel('XXXXX',fontsize = 'large') | |
ax1.set_ylabel('Y111111', fontsize = 'large') | |
ax2 = ax1.twinx() | |
ax2.plot(xticks, size, 'H--r') | |
ax2.set_ylabel('Y222222', fontsize = 'large') | |
plt.tight_layout() | |
plt.savefig("test.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment