Python数据可视化

2019-07-17  本文已影响0人  我的袜子都是洞

数据可视化指的是通过可视化数据表示来探索数据,它与数据挖掘紧密相关,而数据挖掘指的是使用代码来探索数据集的规律和关联。
漂亮的呈现数据关乎的并非仅仅是漂亮的图片。以引人注目的简洁方式呈现数据,让观看者能够明白其含义,发现数据集中原本未识别到的规律和意义。

工具准备matplotlib

matplotlib是一个数学绘图库,可以用它制作简单图表。

安装matplotlib

pip install matplotlib

测试matplotlib

import matplotlib

matplotlib画廊

可以参考官网

绘制简单的折线图

mpl_squares.py

import matplotlib.pyplot as plt 

squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()

修改标签文字和线条粗细

解决标签文字太小,线条太细问题。
mpl_squares.py

import matplotlib.pyplot as plt 

squares = [1, 4, 9, 16, 25]
plt.plot(squares, linewidth=5)

# 设置图表标题
plt.title("Square Numbers", fontsize=24)
# 设置x轴标签和字体大小
plt.xlabel("Value", fontsize=14)
# 设置y轴标签和字体大小
plt.ylabel("Square of Value", fontsize=14)
# 设置刻度标记大小
plt.tick_params(axis='both', labelsize=14)
plt.show()

校正图形

修复4.0的平方是25的情况。
mpl_squares.py

import matplotlib.pyplot as plt 

input_values = [1, 2, 3, 4, 5]
squares = [1, 4, 9, 16, 25]
plt.plot(input_values, squares, linewidth=5)

# 设置图表标题
plt.title("Square Numbers", fontsize=24)
# 设置x轴标签和字体大小
plt.xlabel("Value", fontsize=14)
# 设置y轴标签和字体大小
plt.ylabel("Square of Value", fontsize=14)
# 设置刻度标记大小
plt.tick_params(axis='both', labelsize=14)
plt.show()
Jietu20190717-214621@2x.jpg
上一篇下一篇

猜你喜欢

热点阅读