欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

matplotlib 曲線圖 和 折線圖 plt.plot()實(shí)例

 更新時(shí)間:2020年04月17日 10:14:59   作者:MMmiss葉  
這篇文章主要介紹了matplotlib 曲線圖 和 折線圖 plt.plot()實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

我就廢話不多說(shuō)了,大家還是直接看代碼吧!

繪制曲線:

import time
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000)
y = np.sin(x)
plt.figure(figsize=(6,4))
plt.plot(x,y,color="red",linewidth=1 )
plt.xlabel("x") #xlabel、ylabel:分別設(shè)置X、Y軸的標(biāo)題文字。
plt.ylabel("sin(x)")
plt.title("正弦曲線圖") # title:設(shè)置子圖的標(biāo)題。
plt.ylim(-1.1,1.1)# xlim、ylim:分別設(shè)置X、Y軸的顯示范圍。
plt.savefig('quxiantu.png',dpi=120,bbox_inches='tight')
# plt.show()
# plt.close()

import matplotlib.pyplot as plt
squares=[1,4,9,6,25]
plt.plot(squares)
plt.savefig('zhexiantu.png',dpi=120,bbox_inches='tight') #dpi 代表像素
#繪制折線圖

補(bǔ)充知識(shí):matplotlib 畫(huà)箭頭的兩種方式

如下所示:

def drawArrow(A, B):
 fig = plt.figure(figsize=(5, 5))
 print("xasxcsasdc")
 ax = fig.add_subplot(121)
 # fc: filling color
 # ec: edge color


 """第一種方式"""
 ax.arrow(A[0], A[1], B[0]-A[0], B[1]-A[1],
    width=0.01,
    length_includes_head=True, # 增加的長(zhǎng)度包含箭頭部分
    head_width=0.25,
    head_length=1,
    fc='r',
    ec='b')
 ax.set_xlim(0, 5)
 ax.set_ylim(0, 5)
 ax.grid()
 ax.set_aspect('equal')

 """第二種方式"""
 # 這種方式是在圖上做標(biāo)注時(shí)產(chǎn)生的
 # Example:
 ax = fig.add_subplot(122)
 ax.annotate("",
    xy=(B[0], B[1]),
    xytext=(A[0], A[1]),
    # xycoords="figure points",
    arrowprops=dict(arrowstyle="->", color="r"))
 ax.set_xlim(0, 5)
 ax.set_ylim(0, 5)
 ax.grid()
 ax.set_aspect('equal') #x軸y軸等比例

 #x軸y軸等比例
 plt.show()

第一種

Axes.arrow(x,y,# 坐標(biāo)x, y
dx,dy, # 箭頭兩端橫縱坐標(biāo)距離差
* * kwargs) # 箭頭架構(gòu)和屬性設(shè)置

Constructor arguments
width 箭頭尾巴的線寬
length_includes_head: bool (default: False) # 增加的長(zhǎng)度包含箭頭部分
head_width: float or None (default: 3*width) # 箭頭部分的寬度
head_length: float or None (default: 1.5 * head_width) # 箭頭部分的長(zhǎng)度
shape: [‘full', ‘left', ‘right'] (default: ‘full') # 箭頭是否全部顯示 full 完整顯示 left左半部 right 右半部
overhang: float (default: 0) # 不知道怎么形容 會(huì)改變箭頭部分的形狀

alpha:透明度
color 箭頭的顏色
fc : 箭頭尾部的
ec:箭頭邊界的顏色
fill:箭頭部分是否填充顏色
antialiased :False時(shí)會(huì)讓箭頭部分帶上鋸齒
hatch:箭頭部分的填充形狀

{'/', ‘', ‘|', ‘-', ‘+', ‘x', ‘o', ‘O', ‘.', ‘*'}

第二種

Axes.annotate(s, 標(biāo)注的信息
xy, 標(biāo)注點(diǎn)的坐標(biāo)
*args,
**kwargs)[source]

參數(shù):

s : str 標(biāo)注的信息
xy : (float, float) 標(biāo)注點(diǎn)的坐標(biāo)(箭頭的頭端點(diǎn))
xytext : (float, float), 標(biāo)注的位置(箭頭的尾巴)
arrowprops : dict, optional

標(biāo)注指向的線條的形狀:

‘-' 、 ‘->' 、 ‘-[' 、 ‘|-|' 、 ‘-|>' 、 ‘<-' 、 ‘<->' 、 ‘<|-' 、 ‘<|-|>'、 ‘fancy' 、 ‘simple' 、 ‘wedge' 、

以上這篇matplotlib 曲線圖 和 折線圖 plt.plot()實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • python 爬取京東指定商品評(píng)論并進(jìn)行情感分析

    python 爬取京東指定商品評(píng)論并進(jìn)行情感分析

    本文主要講述了利用Python網(wǎng)絡(luò)爬蟲(chóng)對(duì)指定京東商城中指定商品下的用戶評(píng)論進(jìn)行爬取,對(duì)數(shù)據(jù)預(yù)處理操作后進(jìn)行文本情感分析,感興趣的朋友可以了解下
    2021-05-05
  • 最新評(píng)論