有问题的代码
def plot_hist(plot_data, top_key):
plot_data = plot_data[top_key]
plt.title('Number of emails per week by ' + top_key)
plt.xlabel('Spam emails per week')
plt.ylabel('Frequency')
for key in plot_data:
plt.hist(plot_data[key], bins=20, alpha=0.5, histtype='step', label=key)
plt.legend()
plt.show()
def plot_box(plot_data, top_key):
plot_data = plot_data[top_key]
data = [list_of_weeks for list_of_weeks in plot_data.values()]
plt.title('Spam emails per week by ' + top_key, fontsize=20)
plt.boxplot(data)
plt.xticks([(i + 1) for i in range(len(plot_data.values()))], \
['%s' % i for i in plot_data.keys()], rotation=80)
plt.tight_layout()
plt.savefig(top_key + '/box_plot.png', format='png')
plot_data
是一个嵌套的字典。我正在调用这样的方法:
plot_hist(plot_data, 'platform') # plot the boxplot for platforms
plot_box(plot_data, 'platform') # plot the boxplot for platforms
plot_box(plot_data, 'obfuscation') # plot the boxplot for obfuscations
plot_hist(plot_data, 'obfuscation') # plot the boxplot for obfuscations
问题随之而来plot_hist(plot_data, 'obfuscation')
。我得到这样的直方图:
看?箱线图plot_box(plot_data, 'platform')
与新的直方图相结合。
出了什么问题,我该如何解决?