首页 > 解决方案 > 使用数据生成更漂亮的图

问题描述

我正在寻找所有更漂亮的方法来在任何图中表示我的数据。我希望能得到更多的建议,以便我学习和笔记作为参考。所以请给我提供更多你有任何想法的例子。谢谢你。

import pandas as pd

a = pd.DataFrame({"label":["a","b","c","d"],
                "value1":[2,4,6,8],
                 "value2":[11,12,13,14],
                 "value3":[5,6,7,8]})

fig = plt.figure(figsize=(20,20))

plt.subplot(2, 2, 1)
plt.plot(a.label, a.value1, "r--", linewidth=5, label="a") 
plt.plot(a.label, a.value2, "b-", linewidth=5, label="b")
plt.plot(a.label, a.value3, "g-", linewidth=5, label="c")

plt.legend()
plt.show()

以上是我的情节。但它并不是真的那么好。

标签: pythonmatplotlib

解决方案


import pandas as pd
import matplotlib.pyplot as plt
#only if use jupyter notebook
%matplotlib inline
a = pd.DataFrame({"label":["a","b","c","d"],
                "value1":[2,4,6,8],
                 "value2":[11,12,13,14],
                 "value3":[5,6,7,8]})

fig = plt.figure(figsize=(20,20))

ax=plt.subplot(2, 2, 1)
plt.plot(a.label, a.value1, "r--", linewidth=5, label="a") 
plt.plot(a.label, a.value2, "b-", linewidth=5, label="b")
plt.plot(a.label, a.value3, "g-", linewidth=5, label="c")
#grid on
plt.grid()
#change size of legend
ax.legend(fontsize=20)
#hiding upper and right axis layout
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
#changing the thickness
ax.spines['bottom'].set_linewidth(3)
ax.spines['left'].set_linewidth(3)
#size of axes
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
#setlabels
plt.show()

图像输出: 在此处输入图像描述


推荐阅读