matplotlib 曲線圖 和 折線圖 plt.plot()實(shí)例
我就廢話不多說(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)文章
VScode查看python f.write()的文件亂碼問(wèn)題及解決方法
這篇文章主要介紹了VScode查看python f.write()的文件亂碼問(wèn)題及解決方法,本文通過(guò)圖文并茂的形式給大家分享解決方法,需要的朋友可以參考下2023-02-02python爬蟲(chóng)爬取某網(wǎng)站視頻的示例代碼
這篇文章主要介紹了python爬蟲(chóng)爬取某網(wǎng)站視頻的示例代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02python實(shí)現(xiàn)由數(shù)組生成對(duì)稱(chēng)矩陣
本文給大家分享的是由數(shù)組生成對(duì)稱(chēng)矩陣的思路并附上了使用Python實(shí)現(xiàn)的代碼,希望大家能夠喜歡2021-05-05Python疫情確診折線圖實(shí)現(xiàn)數(shù)據(jù)可視化實(shí)例詳解
數(shù)據(jù)可視化是指用圖形或表格的方式來(lái)呈現(xiàn)數(shù)據(jù)。圖表能夠清楚地呈現(xiàn)數(shù)據(jù)性質(zhì),?以及數(shù)據(jù)間或?qū)傩蚤g的關(guān)系,可以輕易地讓人看圖釋義。用戶通過(guò)探索圖(Exploratory?Graph)可以了解數(shù)據(jù)的特性、尋找數(shù)據(jù)的趨勢(shì)、降低數(shù)據(jù)的理解門(mén)檻2022-09-09使用python進(jìn)行文本預(yù)處理和提取特征的實(shí)例
今天小編就為大家分享一篇使用python進(jìn)行文本預(yù)處理和提取特征的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-06-06PyCharm+Qt Designer+PyUIC安裝配置教程詳解
這篇文章主要介紹了PyCharm+Qt Designer+PyUIC安裝配置教程詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-06-06

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