Python中Matplotlib的點(diǎn)、線形狀、顏色以及繪制散點(diǎn)圖
我們在Python中經(jīng)常使用會(huì)用到matplotlib畫圖,有些曲線和點(diǎn)的形狀、顏色信息長時(shí)間不用就忘了,整理一下便于查找。
安裝matplotlib后可以查看官方說明(太長不貼出來了)
from matplotlib import pyplot as plt help(plt.plot)
常用顏色:
'b' 藍(lán)色
'g' 綠色
'r' 紅色
'c' 青色
'm' 品紅
'y' 黃色
'k' 黑色
'w' 白色
更多顏色:
plt.plot(x, y, marker='+', color='coral')

常用標(biāo)記點(diǎn)形狀:
‘.’:點(diǎn)(point marker)
‘,’:像素點(diǎn)(pixel marker)
‘o’:圓形(circle marker)
‘v’:朝下三角形(triangle_down marker)
‘^’:朝上三角形(triangle_up marker)
‘<‘:朝左三角形(triangle_left marker)
‘>’:朝右三角形(triangle_right marker)
‘1’:(tri_down marker)
‘2’:(tri_up marker)
‘3’:(tri_left marker)
‘4’:(tri_right marker)
‘s’:正方形(square marker)
‘p’:五邊星(pentagon marker)
‘*’:星型(star marker)
‘h’:1號六角形(hexagon1 marker)
‘H’:2號六角形(hexagon2 marker)
‘+’:+號標(biāo)記(plus marker)
‘x’:x號標(biāo)記(x marker)
‘D’:菱形(diamond marker)
‘d’:小型菱形(thin_diamond marker)
‘|’:垂直線形(vline marker)
‘_’:水平線形(hline marker)

常用線形:
‘-‘:實(shí)線(solid line style)
‘–‘:虛線(dashed line style)
‘-.’:點(diǎn)劃線(dash-dot line style)
‘:’:點(diǎn)線(dotted line style)
繪制散點(diǎn)圖
在matplotlib中使用函數(shù) matplotlib.pyplot.scatter 繪制散點(diǎn)圖,matplotlib.pyplot.scatter的函數(shù)細(xì)節(jié):
matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs) x,y組成了散點(diǎn)的坐標(biāo);s為散點(diǎn)的面積;c為散點(diǎn)的顏色(默認(rèn)為藍(lán)色'b');marker為散點(diǎn)的標(biāo)記;alpha為散點(diǎn)的透明度(0與1之間的數(shù),0為完全透明,1為完全不透明);linewidths為散點(diǎn)邊緣的線寬;如果marker為None,則使用verts的值構(gòu)建散點(diǎn)標(biāo)記;edgecolors為散點(diǎn)邊緣顏色。
import matplotlib import matplotlib.pyplot as plt import numpy as np # 保證圖片在瀏覽器內(nèi)正常顯示 %matplotlib inline # 10個(gè)點(diǎn) N = 10 x = np.random.rand(N) y = np.random.rand(N) plt.scatter(x, y) plt.show()
補(bǔ)充:Python散點(diǎn)圖教程
調(diào)整散點(diǎn)大小
N = 10 x = np.random.rand(N) y = np.random.rand(N) area = np.random.rand(N) * 1000 # 包含10個(gè)均勻分布的隨機(jī)值的面積數(shù)組,大小[0, 1000] fig = plt.figure() ax = plt.subplot() ax.scatter(x, y, s=area, alpha=0.5) # 繪制散點(diǎn)圖,面積隨機(jī) plt.show()
調(diào)整散點(diǎn)顏色
N = 10 x = np.random.rand(N) y = np.random.rand(N) x2 = np.random.rand(N) y2 = np.random.rand(N) area = np.random.rand(N) * 1000 fig = plt.figure() ax = plt.subplot() ax.scatter(x, y, s=area, alpha=0.5) ax.scatter(x2, y2, s=area, c='green', alpha=0.6) # 改變顏色 plt.show()
調(diào)整散點(diǎn)形狀
N = 10 x = np.random.rand(N) y = np.random.rand(N) x2 = np.random.rand(N) y2 = np.random.rand(N) x3 = np.random.rand(N) y3 = np.random.rand(N) area = np.random.rand(N) * 1000 fig = plt.figure() ax = plt.subplot() ax.scatter(x, y, s=area, alpha=0.5) ax.scatter(x2, y2, s=area, c='green', alpha=0.6) ax.scatter(x3, y3, s=area, c=area, marker='v', cmap='Reds', alpha=0.7) # 更換標(biāo)記樣式,另一種顏色的樣式 plt.show()
總結(jié)
到此這篇關(guān)于Python中Matplotlib的點(diǎn)、線形狀、顏色以及繪制散點(diǎn)圖的文章就介紹到這了,更多相關(guān)Python Matplotlib繪制散點(diǎn)圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python使用seaborn繪圖直方圖displot,密度圖,散點(diǎn)圖
- python?matplotlib庫繪圖實(shí)戰(zhàn)之繪制散點(diǎn)圖
- Python繪制散點(diǎn)圖之可視化神器pyecharts
- python可視化分析繪制帶趨勢線的散點(diǎn)圖和邊緣直方圖
- python可視化分析繪制散點(diǎn)圖和邊界氣泡圖
- Python+Pyecharts實(shí)現(xiàn)散點(diǎn)圖的繪制
- Python數(shù)據(jù)分析之?Matplotlib?散點(diǎn)圖繪制
- Python繪制簡單散點(diǎn)圖的方法
- Python數(shù)據(jù)可視化制作全球地震散點(diǎn)圖
相關(guān)文章
Windows下Anaconda和PyCharm的安裝與使用詳解
這篇文章主要介紹了Windows下Anaconda和PyCharm的安裝與使用詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
Playwright元素截圖并保存至allure的實(shí)現(xiàn)示例
在UI自動(dòng)化測試中,我們經(jīng)常需要獲取屏幕截圖,本文就介紹一下Playwright元素截圖并保存至allure的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12
ruff check文件目錄檢測--exclude參數(shù)設(shè)置路徑詳解
這篇文章主要為大家介紹了ruff check文件目錄檢測exclude參數(shù)如何設(shè)置多少路徑詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10
Python拼接微信好友頭像大圖的實(shí)現(xiàn)方法
這篇文章主要介紹了Python拼接微信好友頭像大圖的實(shí)現(xiàn)方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08
python實(shí)戰(zhàn)之利用pygame實(shí)現(xiàn)貪吃蛇游戲(二)
這篇文章主要介紹了python實(shí)戰(zhàn)之利用pygame實(shí)現(xiàn)貪吃蛇游戲(二),文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)python的小伙伴們有很好的幫助,需要的朋友可以參考下2021-05-05
使用Python-OpenCV消除圖像中孤立的小區(qū)域操作
這篇文章主要介紹了使用Python-OpenCV消除圖像中孤立的小區(qū)域操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07

