python濡備綍鍋氭牳瀵嗗害鍑芥暟

鍦╬ython涓疄鐜版牳瀵嗗害鍑芥暟锛屽叿浣撴柟娉曞涓嬶細
def KdePlot(x):
import seaborn as sns
import matplotlib.pyplot as plt
# 璁剧疆涓枃鏄剧ず
plt.rcParams['font.sans-serif'] = ['SimHei'] # 涓枃瀛椾綋璁剧疆-榛戜綋
plt.rcParams['axes.unicode_minus'] = False # 瑙e喅淇濆瓨鍥惧儚鏄礋鍙?#39;-'鏄剧ず涓烘柟鍧楃殑闂
# 缁樺埗鏍稿瘑搴﹀垎甯冪洿鏂瑰浘
plt.figure()
sns.set(style='white', # 璁剧疆杈规棰滆壊
font = 'SimHei') # 璁剧疆涓枃瀛椾綋
sns.distplot(x, # 鎸囧畾缁樺浘鏁版嵁
color='orange', # 璁剧疆缁樺浘棰滆壊
kde=True, # 缁樺埗瀵嗗害鏇茬嚎
hist=True, # 缁樺埗鐩存柟鍥?/p>
rug=True, # 缁樺埗 rug 鍥撅紙鍙橀噺鍒嗗竷锛?/p>
kde_kws = {"shade": True, # 杩涜闈㈢Н濉厖
"color": 'darkorange', # 璁剧疆绾挎潯棰滆壊
# 'linewidth': 1.0, # 璁剧疆绾挎潯绮楃粏
'facecolor': 'gray'}, # 璁剧疆濉厖棰滆壊
rug_kws = {'color': 'red', # 璁剧疆 rug 棰滆壊
'height': 0.1}) # 璁剧疆 rug 闀垮害
# vertical = True) # 棰犲€?x-y 杞翠綅缃?/p>
plt.title('鎴戞槸鏍囬') # 璁剧疆鍥剧墖鏍囬
plt.xlabel('Label') # 璁剧疆 x 杞存爣绛?/p>
plt.ylabel('density') # 璁剧疆 y 杞存爣绛?/p>
plt.savefig('out.png', dpi=300) # 瀛樺偍鍥剧墖
plt.show()
# 璇诲彇鏁版嵁
def reader(data):
import pandas as pd
file = pd.read_csv(data, sep='\s+')
data = pd.DataFrame(file, columns=['x', 'value'])
x = data['x']
y = data['value']
return x, y
# 浠g爜鎵ц閮ㄥ垎
data = 'data.txt'
x, y = reader(data)
KdePlot(y)
鏁堟灉鍥撅細

相关问答