繁体   English   中英

matplotlib中的自定义标记

[英]Custom marker in matplotlib

我有一个matplotlib脚本,用于绘制几行,显示8、16、32和64位配置的结果。 该图有点拥挤,为了便于阅读,我想将这些数字添加为标记。 我也更喜欢在文字周围画一个圆圈。 这意味着标记将是带有圆圈的文本。

我的代码是这样的:

#!/usr/bin/env python
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import numpy as np

# Turn off DISPLAY
#matplotlib.use('Agg')
import pylab

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

# T = 16
plt.plot((1,2,3,4),(18.25,15.5,14.15,14.07), linestyle='--', lw=2, marker="D", markersize=7, color='r', label="Stepped Parity 16-bit");
# T = 32
plt.plot((1,2,3,4),(11.90,10.29,9.23,9.11), linestyle='--', lw=2, marker="*", markersize=10, color='r', label="Stepped Parity 32-bit");
# T = 64
plt.plot((1,2,3,4),(6.64,6.20,5.53,5.39), linestyle='--', lw=2, marker="H", markersize=8, color='r', label="Stepped Parity 64-bit");

# T = 16
plt.plot((1,2,3,4),(25.52,22.51,21.05,21.02), linestyle='-', lw=2, marker="D", markersize=7, color='b', label="Interleaving 16-bit");
# T = 32
plt.plot((1,2,3,4),(17.18, 15.13, 13.56, 13.51), linestyle='-', lw=2, marker="*", markersize=10, color='b', label="Interleaving 32-bit");
# T = 64
plt.plot((1,2,3,4),(8.84, 8.31, 7.97, 7.91), linestyle='-', lw=2, marker="h", markersize=8, color='b', label="Interleaving 64-bit");

plt.xlim([0.75, 4.25])
plt.ylim([0, 30])

plt.xticks([1,2,3,4],[512, 1024, 2048, 4096], fontsize=14)
plt.yticks(fontsize=14)

plt.xlabel('# of Words', fontsize=16)
plt.ylabel('Area Overhead', fontsize=16)

# Percentage sign in Y-axis
fmt = '%.0f%%' # Format you want the ticks, e.g. '40%'
yticks = mtick.FormatStrFormatter(fmt)
ax.yaxis.set_major_formatter(yticks)  

plt.legend(ncol=2)

# Save in PDF file
pylab.savefig("Output.pdf", dpi=400, bbox_inches='tight', pad_inches=0.05)

您可以将所有变态的乳胶作为标记,包括文本。 尽管它看起来可能最终看起来很糟糕……但是至少现在您可以选择更多的符号。

plt.plot((1,2,3,4),(11.90,10.29,9.23,9.11), linestyle='--',
         lw=2, marker="$32$", markersize=17, color='r',
         label="Stepped Parity 32-bit")

只要确保按照手册中的说明将它们发送到"$ $"标签内即可。

Python 3 matplotlib 1.3.1 Win7已测试。 另外,请以65个字符的长度换行。 读起来非常舒服。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM