import matplotlib.pyplot as plt
import pandas as pd
objects = ('A', 'B', 'C')
performance = [avgA, avgB, avgC]
exact = plt.plot( performance, alpha=0.5, color= 'purple')
plt.xticks(y_pos, objects)
plt.xlabel('Compression Method')
plt.ylabel('Average Distance b/w Uncompressed & Compressed Point')
plt.title('Evaluation of Different Compression Methods - Averages')
plt.tight_layout()
plt.show()
我的图表有3个问题:
要设置xticks,最好只将plot
作为其第一个参数调用objects
。要设置更多的拍子,MultipleLocator
可用于指示主要和次要刻度线之间的距离(主要刻度线显示一个数字)。
要向绘图中添加文本,只需调用plt.annotate('text', xy=(x,y))
,因为x只是标签,因此x分别为0、1、2。 y是通常的y值。您可以添加许多选项来放置文本,带或不带箭头,对齐等。请参见documentation。
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
avgA, avgB, avgC = 0.009990256984352774, 0.0014206548643907065, 0.055161861569464204
objects = ('A', 'B', 'C')
performance = [avgA, avgB, avgC]
exact = plt.plot( objects, performance, alpha=0.5, color= 'purple')
ax = plt.gca()
ax.yaxis.set_major_locator(MultipleLocator(0.005))
ax.yaxis.set_minor_locator(MultipleLocator(0.001))
for i, avg in enumerate(performance):
plt.annotate(f'{avg:0.3}', xy=(i, avg))
plt.xlabel('Compression Method')
plt.ylabel('Average Distance b/w Uncompressed & Compressed Point')
plt.title('Evaluation of Different Compression Methods - Averages')
plt.tight_layout()
plt.show()