Python matplotlib 쌍 Y 축 곡선 도 를 그 리 는 예제 코드

Matplotlib 소개
Matplotlib 는 매우 강력 한 python 그림 그리 기 도구 입 니 다.
Matplotlib 는 선 그림,산 점 그림,등고선 그림,막대 그림,기둥 그림,3D 도형,도형 애니메이션 등 을 그 릴 수 있 습 니 다.
Matplotlib 설치
pip3 install matplotlib#python3
쌍 X 축의
공유 y 축

ax1=ax.twiny()
ax1=plt.twiny()
쌍 Y 축의
공유 x 축

ax1=ax.twinx()
ax1=plt.twinx()
자동 으로 예 생 성

x = np.arange(0., np.e, 0.01)
y1 = np.exp(-x)
y2 = np.log(x)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y1)
ax1.set_ylabel('Y values for exp(-x)')
ax1.set_title("Double Y axis")
ax2 = ax1.twinx() # this is the important function
ax2.plot(x, y2, 'r')
ax2.set_xlim([0, np.e])
ax2.set_ylabel('Y values for ln(x)')
ax2.set_xlabel('Same X for both exp(-x) and ln(x)')
plt.show()

예:두 Y 축 좌표 의 도 표를 그 렸 다.

# -*- coding: utf-8 -*-

#   
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt

#    
io=r'E:\  \  \       \        .xlsx'
yinka=pd.read_excel(io,sheet_name='YINKA_sample')
bqs=pd.read_excel(io,sheet_name='BQS_result')
yinka_bqs=pd.merge(yinka,bqs,left_on='no',right_on='no',how='inner')

#  
fig,ax=plt.subplots(1,1,figsize=(20, 300))
ax.grid()     #   
x=total.index-1     
#   +1,     ,           
y=total['var1']
ax.plot(x,y,'k--o',alpha=0.5) #    
ax.set_xlim([0,16])    
#  x              x  y      
ax.set_xticks(np.arange(0,16)) #  x      
ax.set_xticklabels(np.arange(0,16),rotation=30) 
#  x     

ax.set_ylim([0,1800])   #  y     
ax.set_yticks(range(0,1800,300))#  y      
ax.set_yticklabels(range(0,1800,300))#  y     

ax.legend(loc='upper left')  #  ax     (legend)
#    
for a,b in zip(x,y):   #     zip       
 ax.text(a,b,b,ha='center',va='bottom',fontsize=15)
#  
ax1=ax.twinx()     
#        y    ,  x ;      x      ax.twiny()
y1=total[['adopt','reject']]
y1.plot.bar(ax=ax1,alpha=0.5) 
#   matplotlib         ,    seaborn      sns.barplot()  ,        
#      y    ,x                ,            
ax1.set_ylim([0,1800])
ax1.set_yticks(range(0,1800,300))
ax1.set_yticklabels(range(0,1800,300))
for e,f,w in zip(data_.index,data_[0],data_[1]):
 ax1.text(e-1,f,f,ha='center',va='bottom',fontsize=10,color='b')
 ax1.text(e-1,w,w,ha='center',va='bottom',fontsize=10,color='g')
ax1.legend(loc='best')
plt.show()   #           #
#    
plt.savefig('path') #       
결과 표시:

총결산
파 이 썬 matplotlib 가 쌍 Y 축 곡선 도 를 그 리 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 파 이 썬 matplotlib 곡선 도 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많은 응원 부 탁 드 리 겠 습 니 다!

좋은 웹페이지 즐겨찾기