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

python實現(xiàn)plt x軸坐標按1刻度顯示

 更新時間:2022年07月14日 09:26:09   作者:Dragon水魅  
這篇文章主要介紹了python實現(xiàn)plt x軸坐標按1刻度顯示,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

plt x軸坐標按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ù),存放縱坐標內容
plt.plot(ls_num)  # y軸變量
plt.ylabel('count')  # y軸名字
plt.show()

matplotlib設置坐標軸

在使用matplotlib模塊時畫坐標圖時,往往需要對坐標軸設置很多參數(shù),這些參數(shù)包括橫縱坐標軸范圍、坐標軸刻度大小、坐標軸名稱等

在matplotlib中包含了很多函數(shù),用來對這些參數(shù)進行設置。

  • plt.xlim、plt.ylim 設置橫縱坐標軸范圍
  • plt.xlabel、plt.ylabel 設置坐標軸名稱
  • plt.xticks、plt.yticks設置坐標軸刻度

以上plt表示matplotlib.pyplot

例子

#導入包
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='--')
#設置坐標軸范圍
plt.xlim((-5, 5))
plt.ylim((-2, 2))
#設置坐標軸名稱
plt.xlabel('xxxxxxxxxxx')
plt.ylabel('yyyyyyyyyyy')
#設置坐標軸刻度
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)

#顯示出所有設置
plt.show()

結果

這里寫圖片描述

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論