-1
%load_ext autoreload
%autoreload 2
%matplotlib inline
import numpy as np
import datetime as dt
import pickle
import pandas as pd
import datetime
from datetime import timedelta, date
from datetime import date as dt
import math
import os
import matplotlib.pyplot as plt
plt.style.use('ggplot')
from pylab import plot,show
from matplotlib import ticker
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.dates as mdates
import pylab as pl
x_min_global=datetime.date(2010,1, 1)- timedelta(days=180)
x_max_global=datetime.date(2015,1, 1)+ timedelta(days=180)
d = pd.DataFrame(0, index=np.arange(155),columns=['Zeros'])
d = pd.DataFrame(0, index=np.arange(2),columns=['Zeros'])
wd=os.getcwd()
def format_date(x, pos=None):
return pl.num2date(x).strftime('%Y-%m-%d')
with PdfPages(wd+'/Plots.pdf') as pdf:
#Plot 1: All
fig = plt.figure(facecolor='white',frameon=True,figsize=(30, 30))
plt.title('Page One ', y=1.08)
axes1 = fig.add_subplot(3,1,1,frameon=False)
axes1.set_xlim(x_min_global,x_max_global)
axes1.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
#Plot line a at 0-level
axes1.plot([x_min_global,x_max_global],d.loc[0:1],color='k', linewidth=2.0, markersize=10.0)
# labels and legend
axes1.set_title('Plot 1')
plt.xlabel('Time', fontsize=10)
plt.ylabel('Y-Values', fontsize=10)
axes1.legend(loc='upper left')
#-----------------------------------------------------------------------
#Plot 2:
axes1 = fig.add_subplot(3,1,2,frameon=False)
axes1.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
#Plot line a at 0-level
axes1.plot([x_min_global,x_max_global],d.loc[0:1],color='k', linewidth=2.0, markersize=10.0)
# labels and legend
axes1.set_title('Plot 2')
plt.xlabel('Time', fontsize=10)
plt.ylabel('Y-Values', fontsize=10)
axes1.legend(loc='upper left')
#-----------------------------------------------------------------------
#Plot 3:
axes2 = fig.add_subplot(3,1,3,frameon=False)
axes2.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
#Plot line a at 0-level
axes2.plot([x_min_global,x_max_global],d.loc[0:1],color='k', linewidth=2.0, markersize=10.0)
# labels and legend
axes2.set_title('Plot 3')
plt.xlabel('Time', fontsize=10)
plt.ylabel('Y-Values', fontsize=10)
axes2.legend(loc='upper left')
pdf.savefig(frameon=False,transparent=False,papertype='a4') # saves the current figure into a pdf page
plt.show()
plt.close()
내 문제는 그림의 축 위에있는 코드로 생성 된 플롯에서 서브 플로트가 겹쳐 보이는 것입니다 (그림에서 빨간색 직사각형 참조). 나는 그림에서 축을 끄려 고 노력했다. 그러나, 나는 그것을 알아낼 수 없었다.Matplotlib.pyplot - 그림에서 축 비활성화./서브 프레임의 축과 그림의 축이 겹침
도움을 주시면 감사하겠습니다. 고맙습니다. 코드/문제의
출력 : 그래도 문제가 해결되지 않으면
plt.axis('off')
를 (또는 무엇을하지 않습니다 완전히 축을 제거하려면
plt.axis ('off')는 x 축과 y 축을 모두 제거합니다. – evtoh
@ s88_py이 정보가 도움이됩니까? 이게 효과가 있었나요? – evtoh
답변 evtoh에 너무 감사드립니다. 그러나 두 가지 제안 모두 내가 원하는 결과를 얻지 못합니다. 위의 제안을 시도하면 0에서 1.0 사이의 값만 하단에 남아 있습니다. 그러나 날짜 값 2010-01-01에서 2015-01-01은 제거됩니다. 다른 제안이 있으십니까? –