Python matplotlib 쌍 Y 축 곡선 도 를 그 리 는 예제 코드
3239 단어 Pythonmatplotlib곡선 도
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 곡선 도 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많은 응원 부 탁 드 리 겠 습 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Python의 None과 NULL의 차이점 상세 정보그래서 대상 = 속성 + 방법 (사실 방법도 하나의 속성, 데이터 속성과 구별되는 호출 가능한 속성 같은 속성과 방법을 가진 대상을 클래스, 즉 Classl로 분류할 수 있다.클래스는 하나의 청사진과 같아서 하나의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.