日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:如何使用python繪制折線圖?

使用python繪制折線圖過程

創(chuàng)新互聯(lián)2013年至今,是專業(yè)互聯(lián)網(wǎng)技術服務公司,擁有項目做網(wǎng)站、網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元資陽做網(wǎng)站,已為上家服務,為資陽各地企業(yè)和個人服務,聯(lián)系電話:13518219792

1、導入庫和設置輸入折線圖數(shù)據(jù)

import numpy as np
import matplotlib.pyplot as plt
# x軸刻度標簽
x_ticks = ['a', 'b', 'c', 'd', 'e', 'f']
# x軸范圍(0, 1, ..., len(x_ticks)-1)
x = np.arange(len(x_ticks))
# 第1條折線數(shù)據(jù)
y1 = [5, 3, 2, 4, 1, 6]
# 第2條折線數(shù)據(jù)
y2 = [3, 1, 6, 5, 2, 4]

2、設置畫布大小并繪制折線

plt.figure(figsize=(10, 6))
# 畫第1條折線,參數(shù)看名字就懂,還可以自定義數(shù)據(jù)點樣式等等。
plt.plot(x, y1, color='#FF0000', label='label1', linewidth=3.0)
# 畫第2條折線
plt.plot(x, y2, color='#00FF00', label='label2', linewidth=3.0)
# 給第1條折線數(shù)據(jù)點加上數(shù)值,前兩個參數(shù)是坐標,第三個是數(shù)值,ha和va分別是水平和垂直位置(數(shù)據(jù)點相對數(shù)值)。
for a, b in zip(x, y1):
    plt.text(a, b, '%d'%b, ha='center', va= 'bottom', fontsize=18)
# 給第2條折線數(shù)據(jù)點加上數(shù)值
for a, b in zip(x, y2):
    plt.text(a, b, '%d'%b, ha='center', va= 'bottom', fontsize=18)
# 畫水平橫線,參數(shù)分別表示在y=3,x=0~len(x)-1處畫直線。
plt.hlines(3, 0, len(x)-1, colors = "#000000", linestyles = "dashed")

3、添加x軸和y軸刻度標簽

plt.xticks([r for r in x], x_ticks, fontsize=18, rotation=20)
plt.yticks(fontsize=18)
# 添加x軸和y軸標簽
plt.xlabel(u'x_label', fontsize=18)
plt.ylabel(u'y_label', fontsize=18)

4、繪制折線圖標題和圖例

# 標題
plt.title(u'Title', fontsize=18)
# 圖例
plt.legend(fontsize=18)

5、保存完成

# 保存圖片
plt.savefig('./figure.pdf', bbox_inches='tight')
# 顯示圖片
plt.show()

網(wǎng)站欄目:創(chuàng)新互聯(lián)Python教程:如何使用python繪制折線圖?
網(wǎng)站地址:http://m.5511xx.com/article/dhsegod.html