保存透明图像时的默认行为是将背景设置为透明,但是我希望背景保持原样,并且图中图形周围的空白也应透明。
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
%load_ext autoreload
%autoreload 2
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
tips = sns.load_dataset("tips")
# Set background of the charts' to be a dark grid.
sns.set_style("darkgrid")
g = sns.FacetGrid(tips, col="smoker", col_order=["Yes", "No"])
g = g.map(plt.hist, "total_bill")
# Save figure with a transparent background (but this unfortunately)
# overrides the dark grid, whereas I want the white surrounding the
# plots to be transparent.
plt.savefig("example.pdf", transparent=True)
答案 0 :(得分:0)
您可以更新matplotlib
的{{1}},使图形背景透明,但保持网格处于活动状态,将其添加到代码中:
rcParams