generate batch chart and save it by matplotlib

知识共享许可协议 Creative Commons
import matplotlib.pyplot as plt
def generate_chart(test_items, compare_axis):
    for item in test_items:
        # ... create title from you item
        plt.title(title)
        plt.grid(True)

        plt.scatter(item.x, item.y)
        plt.xticks(rotation=60)  # not let the x axis to overlap
        plt.ylabel("y axis")
        plt.xlabel(compare_axis)

        range1 = [item.lower_limit, item.high_limit]
        plt.xlim(range1)
        plt.ylim(range1)

        # draw y=x line
        plt.plot(range1, range1)

        # set the grid is a square
        plt.axis([range1[0], range1[1], range1[0], range1[1]], "equal")
        plt.gca().set_aspect("equal")

        plt.tight_layout()  # show up the rotated axis
        #plt.show()

        print("Saving ", item.desc)
        plt.savefig("analog_" + item.desc + ".png")
        plt.clf()

猜你喜欢

转载自blog.csdn.net/lantianjialiang/article/details/91841823