pandas 熊猫图中的标签大小(scatter_matrix)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32121381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
label size in panda plot (scatter_matrix)
提问by Donbeo
How can I set the label size in a pandas plot?
如何在Pandas图中设置标签大小?
In normal plot I do plt.xlabel('a', size=20)
在正常情节我做 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)
回答by CT Zhu
The return of scatter_matrix()is a number of axis, therefore, there is no easy way to set the font size in one pass (except override it using plt.rcParam, such as plt.rcParams['axes.labelsize'] = 20for changing the label size), and it has to be set one by one, such as: plt.setp(axes[0,0].yaxis.get_majorticklabels(), 'size', 15)
的返回scatter_matrix()是多个轴,因此,没有简单的方法可以一次性设置字体大小(除非使用 覆盖它plt.rcParam,例如plt.rcParams['axes.labelsize'] = 20更改标签大小),必须一一设置,例如作为:plt.setp(axes[0,0].yaxis.get_majorticklabels(), 'size', 15)
To have all the tick labels changed, assuming Axes=scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde'):
要更改所有刻度标签,假设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()]


