2015-08-20 163 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种不同的字体大小。 –