Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách thêm tiêu đề trên Seaborn lmplot

Để thêm tiêu đề trên Seaborn Implot, ta thực hiện các bước:

  • Thiết lập kích thước hình và điều chỉnh khoảng đệm giữa và xung quanh subplots.
  • Tạo dataframe Pandas với hai cột, X-Axis và Y-Axis.
  • Dùng phương thức lmplot().
  • Lấy trục hiện tại dùng gca().
  • Hiển thị hình dùng show().

Ví dụ

import pandas
import matplotlib.pylab as plt
import seaborn as sns
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

df = pandas.DataFrame({"X-Axis": [np.random.randint(10) for i in range(10)],
                       "Y-Axis": [i for i in range(10)]})
bar_plot = sns.lmplot(x='X-Axis', y='Y-Axis', data=df, height=3.5)
ax = plt.gca()
ax.set_title("Random Data Implot")
plt.show()

Kết quả

Cách thêm tiêu đề trên Seaborn lmplot