python - 使用数据生成更漂亮的图
问题描述
我正在寻找所有更漂亮的方法来在任何图中表示我的数据。我希望能得到更多的建议,以便我学习和笔记作为参考。所以请给我提供更多你有任何想法的例子。谢谢你。
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()
以上是我的情节。但它并不是真的那么好。
解决方案
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()
推荐阅读
- ios - iOS firebase 安装注册失败
- html - 如何让 div 填充其父级的宽度?
- tesseract - Python 中使用的训练数据导致 Java 中的错误
- python - HTTPException:400 错误请求(错误代码:50074):无法删除社区服务器所需的通道
- python - 在动态链接库中找不到序号 242
- node.js - 如何快速导出路由器内的异步功能?
- autohotkey - 根据 GUI 内容在 AutoHotKey 中构建逻辑
- kotlin - Kotlin Gradle 在构建 jar 时包含运行时
- c++ - 是什么阻止了这个 constexpr 函数的编译时评估?
- javascript - 如何将 console.log 重定向到 Delphi (TEdgeBrowser)