Để hiển thị biểu đồ với giao diện nền tối (dark background) phù hợp cho Jupyter Notebook dark theme, dùng sns.set_style("dark").
Các bước
- Thiết lập figure size và autolayout.
- Áp dụng style "dark": sns.set_style("dark").
- Tạo DataFrame dữ liệu.
- Vẽ barplot bằng sns.barplot().
- Xoay nhãn trục x 45 độ.
- Hiển thị bằ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
sns.set_style("dark")
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.barplot(x='X-Axis', y='Y-Axis', data=df)
plt.xticks(rotation=45)
plt.show()
Kết quả
