2015-02-24 132 views
0

我有一個matplotlib腳本,用於繪製幾行顯示8,16,32和64位配置結果的行。這個圖有點擁擠,爲了更容易閱讀,我想將這些數字添加爲標記。另外我更喜歡圍繞文字圈一圈。這意味着標記將是一個帶有周圍圓圈的文本。matplotlib中的自定義標記

我的代碼是這樣的:

#!/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) 

回答

1

你可以擁有所有的淫乳膠,只要你想你的標誌,包括文字。它可能最終會看起來很糟糕,雖然... 但至少現在你有一個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

Python 3 matplotlib 1.3.1 Win7測試。也請包裝你的線路長度爲65字符。閱讀起來非常舒適。