# 在 Seaborn 圖中設定軸刻度

Manav Narula 2023年1月30日

## 在 Python 中使用 matplotlib.pyplot.set_xtickslabels() 和 matplotlib.pyplot.set_ytickslabels() 函式設定 Seaborn 圖上的軸刻度標籤

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

s_x = [1, 2, 3, 4, 5]
s_y = random.sample(range(0, 100), 5)

df = pd.DataFrame({"s_x": s_x, "s_y": s_y})

g = sns.scatterplot(data=df, y=s_y, x=s_x)
g.set_xticks(range(len(s_x) + 1))
g.set_xticklabels(["0", "a", "b", "c", "d", "e"])

## 在 Python 中使用 matplotlib.pyplot.xticks() 和 matplotlib.pyplot.yticks() 函式設定 Seaborn 圖上的軸刻度標籤

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

s_x = [1, 2, 3, 4, 5]
s_y = random.sample(range(0, 100), 5)

df = pd.DataFrame({"s_x": s_x, "s_y": s_y})

g = sns.scatterplot(data=df, y=s_y, x=s_x)
plt.xticks([1, 2, 3, 4, 5], ["a", "b", "c", "d", "e"])

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.