-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は削除されます。多分他の提案がありますか? –