matploblib绘图刻度内侧,设置字体为新罗马

import matplotlib
import csv
import pandas as pd
from collections import Counter
import matplotlib.pyplot as plt
plt.figure()

def drawPic(counts,marker1,color,label1):
    x = []
    y = []

    for i in counts:
        x.append(i)
        y.append(counts[i])
    print(len(x))
    plt.scatter(x, y,marker=marker1,c=color,label=label1)
    # plt.legend()
    plt.legend(loc='best', prop={"family": "Times New Roman", "size": 16})
    # plt.show()
    # plt.plot(x, y)
    # plt.show()

def readCSV(fileName):
    with open(fileName, 'r') as f:
        reader = csv.reader(f)
        header = next(reader)
        ans = []

        for row in reader:
            ans.append(int(row[-2]))
        # ans.sort()
        return ans

if __name__ == '__main__':
    font = {'family': 'Times New Roman',

            'size': 16,
            }

    matplotlib.rcParams['xtick.direction'] = 'in'
    matplotlib.rcParams['ytick.direction'] = 'in'
    ans = readCSV('./data/e.csv')
    counts = Counter(ans)
    drawPic(counts,'o','r','bad')

    ans = readCSV('./data/liang.csv')
    counts = Counter(ans)
    drawPic(counts,'o','#00CED1','good')


    plt.vlines([50, 150], 0, 14, linestyles='dashed', colors='red')

    plt.xlabel("nodule size",fontdict=font)
    # plt.set(plt.gca, 'FontName', 'Times New Roman', 'FontSize', 7, 'LineWidth', 1.5);

    plt.ylabel("number",fontdict=font)
    # plt.yticks([])
    plt.show()

你可能感兴趣的:(matplotlib,python,开发语言)