我有一个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)
答案 0 :(得分:2)
您可以将所有的乳胶作为您想要的标记,包括文字。它可能最终会看起来非常糟糕...... 但至少现在你有wider arrangement个符号可供选择。
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")
请确保将"$ $"
标记内的described in the manual标记为{{3}}。
Python 3 matplotlib 1.3.1 Win7测试。请将您的线条包裹在65个字符长度。阅读起来非常舒服。