8.基础绘图

版权声明:转载注明出处 https://blog.csdn.net/deephacking/article/details/83053052

1.离散点图

代码:

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


path = 'LogiReg_data.txt'
data = pd.read_csv(path, header=None, names=['Exam1', 'Exam2', 'Admitted'])
# 正例
positive_data = data[data['Admitted'] == 1]
# 负例
negative_data = data[data['Admitted'] == 0]
# 绘图
fig, ax = plt.subplots(figsize=(10, 5))
ax.scatter(positive_data['Exam1'], positive_data['Exam2'], s=30, c='b', marker='o', label='Admitted')
ax.scatter(negative_data['Exam1'], negative_data['Exam2'], s=30, c='r', marker='x', label='Not Admitted')
ax.legend()
ax.set_xlabel('Exam 1 Score')
ax.set_ylabel('Exam 2 Score')
fig.show()

效果

猜你喜欢

转载自blog.csdn.net/deephacking/article/details/83053052