2015-08-20 161 views
3

如何在熊貓圖中設置標籤尺寸?熊貓圖中的標籤尺寸(scatter_matrix)

在正常情節我做plt.xlabel('a', size=20)

In [76]: from pandas.tools.plotting import scatter_matrix 

In [77]: df = DataFrame(randn(1000, 4), columns=['a', 'b', 'c', 'd']) 

In [78]: scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde') 
Out[78]: 
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x9f39e44c>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0x9f39842c>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0x9f383fcc>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0xa58039cc>], 
     [<matplotlib.axes._subplots.AxesSubplot object at 0xa57f19ec>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0xa578e66c>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0xa5adb28c>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0xa5a9deec>], 
     [<matplotlib.axes._subplots.AxesSubplot object at 0xa5d67fec>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0xa5dc764c>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0x9fdb354c>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0x9e63756c>], 
     [<matplotlib.axes._subplots.AxesSubplot object at 0xa5d9ccac>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0x9f6d1ecc>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0xa5d6f02c>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0xa5848e0c>]], dtype=object) 

回答

9

scatter_matrix()返回是一個數軸的,因此,有用於設置在一次通過的字體大小沒有簡單的方法(除了使用plt.rcParam,例如將其覆蓋作爲plt.rcParams['axes.labelsize'] = 20用於改變標籤尺寸),它已被設置一個接一個,如:plt.setp(axes[0,0].yaxis.get_majorticklabels(), 'size', 15)

enter image description here

要使所有的蜱標籤變了,假設Axes=scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')

import pandas as pd 
import matplotlib.pyplot as plt 
from numpy.random import randn 
from pandas.tools.plotting import scatter_matrix 

df = pd.DataFrame(randn(1000, 4), columns=['a', 'b', 'c', 'd']) 

Axes = scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde') 

#y ticklabels 
[plt.setp(item.yaxis.get_majorticklabels(), 'size', 15) for item in Axes.ravel()] 
#x ticklabels 
[plt.setp(item.xaxis.get_majorticklabels(), 'size', 5) for item in Axes.ravel()] 
#y labels 
[plt.setp(item.yaxis.get_label(), 'size', 20) for item in Axes.ravel()] 
#x labels 
[plt.setp(item.xaxis.get_label(), 'size', 3) for item in Axes.ravel()] 

enter image description here

+1

可以包括完整的代碼?我只有matplotlib – Donbeo

+0

的有限知識當然,更新了4種不同的字體大小。 –