Python画图

柱状图

import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
import matplotlib as mpl
import numpy as np

# 中文解码
mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
#Data
y = [92.5, 95.0, 91.0, 93.5, 95.0, 94.0, 94.0, 94.5]
y1 = [7.92, 5.0, 9.0, 6.93, 5.0, 6.0, 5.1, 5.94]
x = np.arange(8)
# 数值显示函数
def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        plt.text(rect.get_x() + rect.get_width() / 2. - 0.2, 1.03 * height, '%s' % float(height))
# 柱状图宽度
bar_width = 0.35
# x轴标签
failure_label = ["A", "B", "C", "D", "E", "F", "G", "H"]
# alpha:透明度
a = plt.bar(x, y, bar_width, align="center", color="c", label="准确率", alpha=0.5)
b = plt.bar(x + bar_width, y1, bar_width, color="red", align="center", label="误报率", alpha=0.5)
# 计算数值
autolabel(a)
autolabel(b)
# x、y轴标签
plt.xlabel("Failure Items")
plt.ylabel("Percent(%)")
plt.title("Failures Detection Evaluation", fontsize=10)
# x轴间隔
plt.xticks(x + bar_width / 2, failure_label)
# y轴间隔
y_major_locator = MultipleLocator(5)
plt.gca().yaxis.set_major_locator(y_major_locator)
# 柱状图标签位置
plt.legend(loc='center right')
plt.show()

Python画图_第1张图片

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

# 中文解码
mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
# Data
TF = [94, 95, 92, 94, 97, 94, 94, 96]  # 真异常
WN = [6,  5,  8,   6, 3,  6,  6,   4]  # 假正常
TN = [94, 96, 91, 94, 96, 95, 96, 96]  # 真正常
WF = [6,  4,  9,   6,  4,  5,  4,  4]  # 假异常
failure_label = ["A", "B", "C", "D", "E", "F", "G", "H"]
x = np.arange(8)
# 柱状图宽度
bar_width = 0.35
fig, ax = plt.subplots(figsize=(10, 7))
# 先创建一根柱子
ax.bar(x, TF, bar_width, align="center", color="blue", label="真异常", alpha=0.5)
# 第二根柱子“堆积”在第一根柱子上方,通过'bottom'调整
ax.bar(x, WN, bar_width, color="red", bottom=TF, align="center", label="假正常", alpha=0.5)
ax.bar(x+bar_width, TN, bar_width, align="center", color="green", label="真正常", alpha=0.5)
ax.bar(x+bar_width, WF, bar_width, color="brown", bottom=TN, align="center", label="假异常", alpha=0.5)
ax.set_title("Failures Detection Evaluation", fontsize=15)
ax.set_xlabel("Failure Items")
ax.set_ylabel("Data Items")
ax.set_xticks(x + bar_width / 2)
ax.set_xticklabels(failure_label)
ax.legend(loc='center right')
plt.show()

Python画图_第2张图片

折线图

import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
plt.xlabel("Video Items")
plt.ylabel("Frequency")
x_data = ['fv', 'nv', 'mv']
y_data = [9, 11, 15]
y_data2 = [9, 38, 18]
ln1, = plt.plot(x_data, y_data, color='red', linewidth=2.0, linestyle='--')
ln2, = plt.plot(x_data, y_data2, color='blue', linewidth=3.0, linestyle='-.')
plt.legend(handles=[ln1, ln2], labels=['FADA', 'noFADA'])
ax = plt.gca()
ax.spines['right'].set_color('none')  # right边框属性设置为none 不显示
ax.spines['top'].set_color('none')  # top边框属性设置为none 不显示
plt.show()

Python画图_第3张图片

import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
x = ['A', 'B', 'C', 'D', 'E', 'F']
y = [96, 98, 97, 98, 95, 96]
y2 = [94, 97, 95, 97, 96, 95]
plt.figure(figsize=(7, 4))  # 画布大小
ln1, = plt.plot(x, y, 'b', lw=1.5)  # 蓝色的线
ln2, = plt.plot(x, y2, 'g', lw=1.5)  # 绿色的线
plt.legend(handles=[ln1, ln2], labels=['oldVQA', 'newVQA'])
plt.plot(y, 'ro')  # 离散的点
plt.plot(y2, 'ro')  # 离散的点
plt.grid(True)
plt.axis('tight')
plt.xlabel('Failure Items')
plt.ylabel('Percent(%)')
plt.title('准确率')
plt.show()

Python画图_第4张图片

热力图

import matplotlib.pyplot as plt
import seaborn as sns
# fmt(字符串格式代码,矩阵上标识数字的数据格式,比如保留小数点后几位数字)
sns.set()
x = [[0.756, 0.67, 0.59], [0.66, 0.63, 0.72], [0.73, 0.69, 0.57]]  
ax = sns.heatmap(x, annot=True, vmax=1, vmin=0)
ax.set_title("Memory Utilization After Scheduler")
b = ax.get_figure()
plt.show()

Python画图_第5张图片

你可能感兴趣的:(python,数据统计图)