本文整理匯總了Python中matplotlib.patheffects方法的典型用法代碼示例。如果您正苦於以下問題:Python matplotlib.patheffects方法的具體用法?Python matplotlib.patheffects怎麽用?Python matplotlib.patheffects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib
的用法示例。
在下文中一共展示了matplotlib.patheffects方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: scatter_with_legend
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import patheffects [as 別名]
def scatter_with_legend(
fig, ax, df, font_color, x, y, c, cmap, legend, **scatter_kwargs
):
import seaborn as sns
import matplotlib.patheffects as PathEffects
unique_labels = np.unique(c)
if legend == "on data":
g = sns.scatterplot(
x, y, hue=c, palette=cmap, ax=ax, legend=False, **scatter_kwargs
)
for i in unique_labels:
color_cnt = np.nanmedian(df.iloc[np.where(c == i)[0], :2], 0)
txt = ax.text(
color_cnt[0],
color_cnt[1],
str(i),
color=font_color,
zorder=1000,
verticalalignment="center",
horizontalalignment="center",
weight="bold",
) # c
txt.set_path_effects(
[
PathEffects.Stroke(
linewidth=1.5, foreground=font_color, alpha=0.8
), # 'w'
PathEffects.Normal(),
]
)
else:
g = sns.scatterplot(
x, y, hue=c, palette=cmap, ax=ax, legend="full", **scatter_kwargs
)
ax.legend(loc=legend, ncol=unique_labels // 15)
return fig, ax