(1) 折线图
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
plt.rcParams['figure.figsize'] = (9,6)
data1 = pd.read_csv(r"throughput_6kweb.csv")
plt.plot(data1['Snort'],data1['AVG_throughput'], label='Snort', color='blue', marker='o', linestyle='solid')
plt.xlabel('# of Snort')
plt.ylabel('Avg Throughput(Req/sec)')
plt.title('Performance')
plt.legend()
plt.show()

(2)多个折线图
1. 读数据
#Read data
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
plt.rcParams['figure.figsize'] = (9,6)
data1 = pd.read_csv(r"SW-wrk7.csv")
data1
2. 画图
plt.plot(data1['Skewness'], data1['MM_W'], label='Weight', color='darkcyan', marker='o', linestyle='solid')
plt.plot(data1['Skewness'],data1['MM_RSS'], label='RSS', color='orange', marker='o', linestyle='solid')
plt.xlabel('Skewness Level')
plt.ylabel('Max/Min')
plt.title('Max/Min of Weight and RSS')
plt.legend()
plt.show()
(3)柱状图
但是横坐标格式不够好
plt.xlabel("Traffic Skewness")
plt.ylabel("JFI")
plt.title("JFI of Weight and RSS")
#plt.bar(data1['LightFlows'],data1['RSS'], width=0.3, label='RSS', color = 'red')
#plt.bar(data1['LightFlows']+0.4,data1['Weight'], width=0.3, label='Weight', color = 'blue')
plt.bar(data1['Skewness'],data1['JFI_W'], width=0.4, label='Weight', color = 'darkcyan')
plt.bar(data1['Skewness']+0.4,data1['JFI_RSS'], width=0.4, label='RSS', color = 'orange')
plt.legend(loc='upper right', frameon=False)
(4)对横坐标进行格式化的柱状图(推荐)
x = data1['Skewness']
y = data1['JFI_W']
y1 = data1['JFI_RSS']
width = 0.4
#x = np.arange(len(x))
fig,ax = plt.subplots()
weight = ax.bar(x,y,width,color='darkcyan')
rss = ax.bar(x+width, y1, width, alpha=0.9, color='orange')
ax.set_xticks(x + width/2)#将坐标设置在指定位置
ax.set_xticklabels(x)#将横坐标替换成
ax.set_xlabel('Skewness Level')
ax.set_ylabel('JFI')
ax.set_title('JFI of Weight and RSS')
plt.legend([weight,rss],['Weight','RSS'],loc='upper right')

本文介绍了如何在Jupyter环境中利用数据绘制简单易懂的折线图和柱状图,包括单个折线图、多个折线图的绘制,以及柱状图的创建,特别是针对横坐标格式的优化处理。
3419

被折叠的 条评论
为什么被折叠?



