分享一个在python中画图, 并在图中增加网格线和将x轴标签倾斜的小程序
程序员文章站
2024-03-26 14:03:35
...
如题目所述, 分享一个在图中增加网格线, 并且将x轴标签倾斜的python小程序. 小程序的源码如下:
from 翻译包 import *
import matplotlib
import matplotlib.pyplot as plt
font = {'size':26}
matplotlib.rc('font', **font)
markersize = 18
横坐标 = 范围(1, 9)
纵坐标 = [5, 8, 4, 2, 3, 1, 6, 4]
图标大小 = 100
线条宽度 = 2.0
fig = plt.figure(1)
plt.grid(linestyle=":")
plt.scatter(横坐标, 纵坐标, label = "SF.sw", color = 'blue', \
linewidths = 线条宽度, marker="^", s = 图标大小, facecolors="none")
plt.xticks(横坐标, ["CAIDA", "Cmps", "ISP1", "ISP2", r"CAIDA$_{v6}$", r"Cmps$_{v6}$", r"ISP1$_{v6}$", r"ISP2$_{v6}$"], rotation=70)
plt.xlabel("Traces")
plt.ylabel("Throughput/Mpps")
plt.savefig("测试.pdf", bbox_inches = "tight")
plt.savefig("测试.png", bbox_inches = "tight")
plt.savefig("测试.eps", bbox_inches = "tight")
plt.close()
其输出结果如下
其中, 画网格的命令为(参考此处):
# matplotlib.pyplot.grid(b=None, which='major', axis='both', **kwargs)
grid(color='r', linestyle='-', linewidth=2)
# linestyle的值可为{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
使x轴坐标倾斜的命令为:
xticks(rotation=90)