網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
plt x軸坐標(biāo)按1刻度顯示
import matplotlib.pyplot as plt from matplotlib.pyplot import MultipleLocator x_major_locator = MultipleLocator(1) ax = plt.gca() ax.xaxis.set_major_locator(x_major_locator) # x軸按1刻度顯示 # ls_num是你已有的列表數(shù)據(jù),存放縱坐標(biāo)內(nèi)容 plt.plot(ls_num) # y軸變量 plt.ylabel('count') # y軸名字 plt.show()
matplotlib設(shè)置坐標(biāo)軸
在使用matplotlib模塊時(shí)畫坐標(biāo)圖時(shí),往往需要對(duì)坐標(biāo)軸設(shè)置很多參數(shù),這些參數(shù)包括橫縱坐標(biāo)軸范圍、坐標(biāo)軸刻度大小、坐標(biāo)軸名稱等
在matplotlib中包含了很多函數(shù),用來(lái)對(duì)這些參數(shù)進(jìn)行設(shè)置。
-
plt.xlim
、plt.ylim
設(shè)置橫縱坐標(biāo)軸范圍 -
plt.xlabel
、plt.ylabel
設(shè)置坐標(biāo)軸名稱 -
plt.xticks
、plt.yticks
設(shè)置坐標(biāo)軸刻度
以上plt表示matplotlib.pyplot
例子
#導(dǎo)入包 import matplotlib.pyplot as plt import numpy as np #創(chuàng)建數(shù)據(jù) x = np.linspace(-5, 5, 100) y1 = np.sin(x) y2 = np.cos(x) #創(chuàng)建figure窗口 plt.figure(num=3, figsize=(8, 5)) #畫曲線1 plt.plot(x, y1) #畫曲線2 plt.plot(x, y2, color='blue', linewidth=5.0, linestyle='--') #設(shè)置坐標(biāo)軸范圍 plt.xlim((-5, 5)) plt.ylim((-2, 2)) #設(shè)置坐標(biāo)軸名稱 plt.xlabel('xxxxxxxxxxx') plt.ylabel('yyyyyyyyyyy') #設(shè)置坐標(biāo)軸刻度 my_x_ticks = np.arange(-5, 5, 0.5) my_y_ticks = np.arange(-2, 2, 0.3) plt.xticks(my_x_ticks) plt.yticks(my_y_ticks) #顯示出所有設(shè)置 plt.show()
結(jié)果
原文鏈接:https://blog.csdn.net/qq_43650934/article/details/107084429
相關(guān)推薦
- 2022-11-25 淺析Golang中的內(nèi)存逃逸_Golang
- 2022-12-24 Kubernetes?ApiServer三大server權(quán)限與數(shù)據(jù)存儲(chǔ)解析_云和虛擬化
- 2022-07-09 Python?操作?Excel?之?openpyxl?模塊_python
- 2022-10-29 C++通過Makefile定義宏參數(shù),傳入程序
- 2022-10-07 Rust中的Struct使用示例詳解_相關(guān)技巧
- 2022-11-29 React?props全面詳細(xì)解析_React
- 2022-09-04 go語(yǔ)言中的面向?qū)ο骭Golang
- 2022-06-12 C#集合之有序列表的用法_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支