生成的图形正在重叠

时间:2016-03-11 13:57:08

标签: python-2.7 matplotlib graph

我尝试了下面的代码我得到了data_set1_decision的完美图表,只为其他图表重叠了我的意思是第二张图是绘制第一张图,但我希望它在一个新的图表中并保存任何帮助

import pandas as pd
import numpy as np
import csv as csv
import matplotlib.pyplot as plt

def visualize_the_data_sets_results(method,set,feature):
    x2 = np.linspace(0, 3.5,80)
    poly_deg2 = 3
    coefs2 = np.polyfit([1,2,3], method, poly_deg2)
    y_poly2 = np.polyval(coefs2, x2)

    plt.style.use('ggplot')
    plt.plot([1,2,3], method, "o")
    plt.plot(x2, y_poly2)
    plt.ylabel("prediction_accuracy")
    plt.xlabel("features")

    plt.show()

    if set == 1 and feature == 1:
        plt.savefig('C:\Users\mullapudi\Desktop\project\static\\data_set1_decision.png')

    if set == 1 and feature == 2:
        plt.savefig('C:\Users\mullapudi\Desktop\project\static\\data_set2_decision.png')

    if set == 1 and feature == 3:
        plt.savefig('C:\Users\mullapudi\Desktop\project\static\\data_set3_decision.png')

    if set == 1 and feature == 4:
        plt.savefig('C:\Users\mullapudi\Desktop\project\static\\data_set4_decision.png')

if __name__ == "__main__":
    data_set1_decision=[10,20,30]
    data_set2_decision=[40,50,60]
    data_set3_decision=[70,80,90]
    data_set4_decision=[25,50,75]

    visualize_the_data_sets_results(data_set1_decision,1,1)
    visualize_the_data_sets_results(data_set2_decision,1,2)
    visualize_the_data_sets_results(data_set3_decision,1,3)
    visualize_the_data_sets_results(data_set4_decision,1,4)

1 个答案:

答案 0 :(得分:0)

如果要确保为连续绘图创建新图形,则需要在绘图函数的开头显式调用figure构造函数

fig = plt.figure()