python - FacetGrid 的 Matplotlib 轴

标签 python matplotlib seaborn axes facet-grid

为什么 https://seaborn.pydata.org/generated/seaborn.FacetGrid.html

没有像其他图表一样接受 matplotlib 轴的 ax 参数

例如,https://seaborn.pydata.org/generated/seaborn.distplot.html

因为我需要为 FacetGrid 设置 matplotlib 轴以引入自定义样式。

最佳答案

FaceGrid 制作网格,因此您无法将网格传递给它。各个图都存储在内部,并且可以像下面的代码一样进行操作。另请注意 Axes and Axis are different in Matplotlib 。下面的代码展示了获取 Axes 和 Axis 的方法:

import seaborn as sns
import pandas as pd

#dummy data
data= pd.DataFrame(data={'a':np.random.randint(0,2, 100),
                         'b':np.random.rand(100),
                         'c':np.random.rand(100)})

# make facetgrid and store in variable
g = sns.FacetGrid(data, col='a') # make facetgrid with 2 columns, because there are two distinct values in column a of data
g.map(plt.scatter, 'b', 'c') # map function to grid

# the individual axes of the grid are stored in g.
# you can access and edit them like so:

for ax in g.axes[0]:
    ax.set_ylabel('test')
    ax.set_ylim(0,1.5)
    ax.set_title('title')
    # now you can obtain the axis from one of the axes
    x_axis = ax.get_xaxis()

enter image description here

关于python - FacetGrid 的 Matplotlib 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62100983/

相关文章:

python - 在 Python 中求解一个困难的(多项式?)方程

python - 理解Python的导入__main__

python - Bash if else 然后与 bash 版本的 sys.exit() 在一行中

python - Pandas :将多列绘制为相同的 x 值

numpy - 将 2D NumPy 数组转换为用于绘制直方图的一维数组

python - matplotlib 1.4.2 与 Seaborn : line markers not functioning

python - matplotlib 和 seaborn 热图在 Jupyter 中与 savefig 的渲染方式不同(标签被切断)

python - 在字典的字典中查找最小元素

python - 安装matplotlib出现Permission denied错误

python - Seaborn:线图看起来像阶梯图