python數據可視化,幾個最簡單的例子


import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

# 簡單的折線圖繪制
# x = [1, 2 ,3 ,4, 5]
# y = [1, 4, 9, 16, 25]
# plt.plot(x, y, linewidth = 5)
# plt.title('example code', fontsize = 40, color = 'red')
# plt.xlabel('value',fontsize = 20, color = 'blue')
# plt.ylabel('vertical', fontsize = 20, color = 'blue')
# plt.tick_params(axis = 'both', labelsize = 14)
# plt.show()

# 散點圖繪制
# x = [1, 2, 3]
# y = [2, 4, 6]
# plt.scatter(x, y, color = 'red', s = 2000)
# plt.show()

# 繪制加了顏色隨某一變量變化的散點圖
# x = list(range(1, 1001))
# y = [n**2 for n in x]
# # c=y,設置顏色變量隨y值而變化,cmp=...設置顏色值
# plt.scatter(x, y, c = y, cmap = plt.cm.Reds, s = 80)
# plt.show()


# 應用seaborn模塊設置主題樣式
# sns.set_style('whitegrid')
# x = list(range(1, 1001))
# y = [n**2 for n in x]
# # c=y,設置顏色變量隨y值而變化,cmp=...設置顏色值
# plt.scatter(x, y, c = y, cmap = plt.cm.Reds, s = 80)
# plt.show()

#讀取txt格式文件並繪制直方圖
df_iris = pd.read_table('df_iris.txt')
# sns.distplot(df_iris['petal_length'],kde = True)
plt.plot(df_iris['petal_length'],df_iris['petal_width'])
plt.show()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM