尝试在中将标签设置为大写
Seaborn violin
情节
当这起作用时:
test = pd.DataFrame(data={"one": [5, 6, 7, 8], "two": ["a", "b", "c", "d"]})
ax = sns.violinplot(x=test["two"], y=test["one"])
labels = [item.get_text().upper() for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)
这不会:
test = pd.DataFrame(data={"one": [5, 6, 7, 8], "two": ["a", "b", "c", "d"]})
ax = sns.violinplot(x=test["two"], y=test["one"])
fmt = lambda x, _: str(x).upper()
ax.xaxis.set_major_formatter(mtick.FuncFormatter(fmt))
第二个代码返回0、1、2、3,而不是预期的A、B、C、D。
为什么?
我正在按如下方式导入库:
import pandas as pd # v1.3.5
import seaborn as sns # v0.11.2
import matplotlib.pyplot as plt # v3.4.3
import matplotlib.ticker as mtick # v3.4.3