分享一个在python的matplotlib中插入希腊字母的例子

本文展示了如何在使用matplotlib进行Python绘图时插入希腊字母,例如通过r"$alpha$=0.8"的语法来表示α等于0.8。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如题所述,以下分享一个用python的matplotlib包画图的时候在图中插入希腊字母的例子,简单说就是用r"$\alpha$=0.8"这样的形式,注意最开始的字母r不能丢。

import json
import matplotlib.pyplot as plt
import matplotlib
#import np
from matplotlib.patches import Ellipse

font = {'size':18}
matplotlib.rc('font', **font)

src1 = "./cdf.caida.20180315-125910.json"
src2 = "./cdf.caida.20180315-130000.json"
src3 = "./cdf.hgc.20080415000.json"
src4 = "./cdf.hgc.20080415001.json"
src5 = "./zipf_dist_1.json"
src6 = "./zipf_dist_2.json"

if __name__ == "__main__":
	with open(src1, "r") as f:
		[idx1, cdf1] = json.load(f)
	with open(src2, "r") as f:
		[idx2, cdf2] = json.load(f)
	with open(src3, "r") as f:
		[idx3, cdf3] = json.load(f)
	with open(src4, "r") as f:
		[idx4, cdf4] = json.load(f)
	with open(src5, "r") as f:
		[idx5, cdf5] = json.load(f)
	with open(src6, "r") as f:
		[idx6, cdf6] = json.load(f)

	plt.figure(1)
#	plt.title("Heavy Hitters ARE")
#	plt.xticks(range(5), ("1M", "5M", "10M", "15M", "20M"))
	plt.ylim(0, 1.05)
	plt.plot(idx1, cdf1, label = "CAIDA1", marker = "x", mfc="none")
	plt.plot(idx2, cdf2, label = "CAIDA2", marker = "s", mfc="none")
	plt.plot(idx3, cdf3, label = "ISP1", marker = "o", mfc="none")
	plt.plot(idx4, cdf4, label = "ISP2", marker = "1", mfc="none")
	plt.plot(idx5, cdf5, label = r"zipf $\alpha$=0.8", marker = "p", mfc="none")
	plt.plot(idx6, cdf6, label = r"zipf $\alpha$=1.1", marker = "d", mfc="none")
#	plt.plot(range(5), are_hw, label = "Hardware", marker = "o")
#	plt.legend(bbox_to_anchor=(0.0, 1.02, 1.0, 0.102), loc = 3, ncol = 2, mode = "expand", borderaxespad = 0.0)
	plt.legend(loc = 4)
	plt.xlabel("Proportion of Flows")
	plt.ylabel("Proportion of Packets")
	plt.savefig("cdf.pdf", bbox_inches = "tight")
	plt.savefig("cdf.png", bbox_inches = "tight")

其运行结果如下:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值