2017-06-12 9 views
0

何らかの理由で、x軸ラベルを上軸にプロットしたいとします。しかし、フォントサイズのパラメータは、以下のコードで変更することはできません。私は参照用に2つのサブプロットをプロットしました。 Xトップ軸のlableのフォントサイズを変更する方法を従ってMatPlotLibのトップx軸のフォントサイズを変更する

f =plt.figure(figsize = (12,6)) 
ax1 = plt.subplot(211) 


ax1.plot(np.arange(0,10,1),np.arange(0,10,1)) 

ax1.xaxis.set_ticks_position('both') 
ax1.yaxis.set_ticks_position('both') 

ax1.tick_params(axis='x', which='both', labeltop ='on',labelbottom = 'off')  
for tick in ax1.xaxis.get_major_ticks(): 
    tick.label.set_fontsize(24) 


ax2 = plt.subplot(212) 

ax2.plot(np.arange(0,10,1),np.arange(0,10,1)) 

ax2.xaxis.set_ticks_position('both') 
ax2.yaxis.set_ticks_position('both') 

ax2.tick_params(axis='x', which='both', labeltop ='off',labelbottom = 'on')  
for tick in ax2.xaxis.get_major_ticks(): 
    tick.label.set_fontsize(24) 

enter image description here

、?

ご了承ください。

答えて

0

ax1.xaxis.get_major_ticks()のラベルを反復すると、下のラベルだけが表示されるようです。上部と下部の両方のラベルのフォントサイズを設定するには、私のためにset_tick_paramsが機能しました。

import numpy as np 
import matplotlib.pyplot as plt 

f =plt.figure(figsize = (12,6)) 
ax1 = plt.subplot(211) 

ax1.plot(np.arange(0,10,1),np.arange(0,10,1)) 

ax1.xaxis.set_ticks_position('both') 
ax1.yaxis.set_ticks_position('both') 

ax1.tick_params(axis='x', which='both', labeltop ='on',labelbottom = 'off') 
ax1.xaxis.set_tick_params(labelsize=24) 

plt.show() 
0

ティックの反復処理ではなく、キーワード引数labelsizeを使用してください。

f = plt.figure(figsize = (12, 6)) 

ax1 = plt.subplot(211) 
ax1.plot(np.arange(0, 10, 1),np.arange(0, 10, 1)) 

ax1.xaxis.set_ticks_position('both') 
ax1.yaxis.set_ticks_position('both') 
ax1.tick_params(axis='x', which='both',  
       labeltop='on', labelbottom='off', labelsize=27) 


ax2 = plt.subplot(212) 
ax2.plot(np.arange(0, 10, 1), np.arange(0, 10, 1)) 

ax2.xaxis.set_ticks_position('both') 
ax2.yaxis.set_ticks_position('both') 
ax2.tick_params(axis='x', which='both', 
       labeltop='off', labelbottom='on', labelsize=14) 
関連する問題