python可视化笔记

pandas plot官方文档

1、图片输出中文字题

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']

不行的话可以参考https://tangxing.blog.csdn.net/article/details/108843288?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1.pc_relevant_default&utm_relevant_index=2 设置不同的字体试试。

2、绘制多个subplot

数据如下:


fig = plt.figure(figsize=(10,6), dpi=200)

ax1 = plt.subplot(221)
df_hw_pv[["ecpm_0", "ecpm_1"]].plot(ax=ax1)
# 设置标题
# ax1.set_title("eCPM")

ax2 = plt.subplot(222)
df_hw_pv[["ctr_0", "ctr_1"]].plot(ax=ax2)

ax3 = plt.subplot(223)
df_hw_pv[["cvr_0", "cvr_1"]].plot(ax=ax3)

ax4 = plt.subplot(224)
df_hw_pv[["ctcvr_0", "ctcvr_1"]].plot(ax=ax4)

fig.tight_layout()

plt.show();

3、不均匀分割子图

f, (a0, a1) = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1, 3]}, figsize=(10,8))

df22.set_index("website_id").plot(kind="barh", ax=a1)
a1.set_xlabel("count")

df33.set_index("date").plot(kind="bar", ax=a0, rot=0)
plt.savefig("shoubai_website_dist.png")

4、设置x坐标轴标签

参考:https://stackoverflow.com/questions/11244514/modify-tick-label-text

x_ticks = ["2022-04-01","2022-04-02","2022-04-03","2022-04-04","2022-04-05","2022-04-06","2022-04-07","2022-04-08","2022-04-09",
          "2022-04-10(sunday)","2022-04-11","2022-04-12","2022-04-13","2022-04-14","2022-04-15","2022-04-16","2022-04-17(sunday)","2022-04-18",
          "2022-04-19","2022-04-20","2022-04-21","2022-04-22"]

ax = df.plot(figsize=(15,8))

_ = ax.set_xlabel("dt")
_ = ax.set_ylabel("ciliu rate")
_ = ax.set_xticks(np.arange(len(x_ticks)))
_ = ax.set_xticklabels(x_ticks, rotation=90)

你可能感兴趣的:(python可视化笔记)