在上一篇文章中,小编为您详细介绍了关于《pcb布线都是交叉咋解决啊20?联想电脑一体机C560型号开关电路板价格大概是多少》相关知识。本篇中小编将再为您讲解标题使用Python绘图库Matplotlib绘图时?matplotlib如何自定义显示背景。

坐标轴范围设置
坐标轴范围的设置通常有两种方法,第①种为通过axes.set_xbound和axes.set_ybound对X轴和Y轴进行分别设置,第②种为通过axes.set_xlim和axes.set_ylim方法对X轴和Y轴进行分别设置。
这两种方法虽然都能改变坐标轴刻度范围,但是在使用的时候却有差别。
① · axes.set_xbound和axes.set_ybound方法
axes.set_xbound(lower, upper)
axes.set_ybound(lower, upper)
axes.set_xbound和axes.set_ybound方法有两个参数值,这两个参数值不分先后,大的值代表坐标轴的最大值,小的值为坐标轴最小值。
方法实例:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.image as img
mpl.rcParams[\'ytick.color\']=\'white\'
mpl.rcParams[\'xtick.color\']=\'white\'
mpl.rcParams[\'ytick.labelsize\']=\'large\'
mpl.rcParams[\'xtick.labelsize\']=\'large\'
mpl.rcParams[\'axes.edgecolor\']=\'white\'
x = np.linspace(⓪.⓪ · ⑤.⓪)
y = np.cos(② * np.pi * x) * np.exp(-x)
fig, ax = plt.subplots(nrows=① · ncols=②)
bgimg = img.imread(\'picture.png\')
fig.figimage(bgimg)
fig.subplots_adjust(left=⓪.⓪⑤ · right=⓪.⑨⑤ · top=⓪.⑨⑤ · bottom=⓪.⓪⑤ · wspace=⓪.①②)
ax[⓪].set_facecolor(\'None\')
ax[⓪].plot(x,y,\'o-\',color=\'gold\')
ax[①].set_facecolor(\'None\')
ax[①].plot(x,y,\'o-\',color=\'gold\')
ax[①].set_ybound(-⓪.③ · ⓪.⑤)
plt.show()
② · axes.set_xlim和axes.set_ylim方法
axes.set_xlim(left, right)
axes.set_ylim(bottom, top)
axes.set_xlim和axes.set_ylim方法我们已经在坐标轴方向中讲过,他们的参数分别为X轴左端点值、右端点值和Y轴底部端点值、顶部端点值,所以只要给定参数值就设定好了坐标轴范围。
方法实例:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.image as img
mpl.rcParams[\'ytick.color\']=\'white\'
mpl.rcParams[\'xtick.color\']=\'white\'
mpl.rcParams[\'ytick.labelsize\']=\'large\'
mpl.rcParams[\'xtick.labelsize\']=\'large\'
mpl.rcParams[\'axes.edgecolor\']=\'white\'
x = np.linspace(⓪.⓪ · ⑤.⓪)
y = np.cos(② * np.pi * x) * np.exp(-x)
fig, ax = plt.subplots(nrows=② · ncols=①)
bgimg = img.imread(\'picture.png\')
fig.figimage(bgimg)
fig.subplots_adjust(left=⓪.⓪⑤ · right=⓪.⑨⑤ · top=⓪.⑨⑤ · bottom=⓪.⓪⑤ · hspace=⓪.①②)
ax[⓪].set_facecolor(\'None\')
ax[⓪].plot(x,y,\'o-\',color=\'gold\')
ax[①].set_facecolor(\'None\')
ax[①].plot(x,y,\'o-\',color=\'gold\')
ax[①].set_xlim(① · ④)
plt.show()
需要注意的是
当我们需要使用axes.set_xscale方法改变X轴比例尺时,axes.set_xbound方法和axes.set_xlim方法必须在axes.set_xscale方法之后使用才能正常显示。
当我们需要使用axes.invert_xaxis方法对坐标轴方向进行改变时,使用axes.set_xbound方法并不会对axes.invert_xaxis方法产生影响;而axes.set_xlim方法与axes.invert_xaxis方法互相影响,位置靠后的代码效果会覆盖位置靠前的代码效果。
对比实例:
① · 左图axes.set_xbound方法在axes.set_xscale方法之后使用,右图axes.set_xbound方法在axes.set_xscale方法之前使用
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.image as img
mpl.rcParams[\'ytick.color\']=\'white\'
mpl.rcParams[\'xtick.color\']=\'white\'
mpl.rcParams[\'ytick.labelsize\']=\'large\'
mpl.rcParams[\'xtick.labelsize\']=\'large\'
mpl.rcParams[\'axes.edgecolor\']=\'white\'
x = np.linspace(⓪.⓪ · ⑤.⓪)
y = np.cos(② * np.pi * x) * np.exp(-x)
fig, ax = plt.subplots(nrows=① · ncols=②)
bgimg = img.imread(\'picture.png\')
fig.figimage(bgimg)
fig.subplots_adjust(left=⓪.⓪⑤ · right=⓪.⑨⑤ · top=⓪.⑨⑤ · bottom=⓪.⓪⑤ · wspace=⓪.①②)
ax[⓪].set_facecolor(\'None\')
ax[⓪].plot(x,y,\'o-\',color=\'gold\')
ax[⓪].set_xscale(\'log\',basex=②)
ax[⓪].set_xbound(⓪ · ④)
ax[①].set_facecolor(\'None\')
ax[①].plot(x,y,\'o-\',color=\'gold\')
ax[①].set_xbound(⓪ · ④)
ax[①].set_xscale(\'log\',basex=②)
plt.show()
② · 左图axes.set_xlim方法在axes.set_xscale方法之后使用,右图axes.set_xlim方法在axes.set_xscale方法之前使用
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.image as img
mpl.rcParams[\'ytick.color\']=\'white\'
mpl.rcParams[\'xtick.color\']=\'white\'
mpl.rcParams[\'ytick.labelsize\']=\'large\'
mpl.rcParams[\'xtick.labelsize\']=\'large\'
mpl.rcParams[\'axes.edgecolor\']=\'white\'
x = np.linspace(⓪.⓪ · ⑤.⓪)
y = np.cos(② * np.pi * x) * np.exp(-x)
fig, ax = plt.subplots(nrows=① · ncols=②)
bgimg = img.imread(\'picture.png\')
fig.figimage(bgimg)
fig.subplots_adjust(left=⓪.⓪⑤ · right=⓪.⑨⑤ · top=⓪.⑨⑤ · bottom=⓪.⓪⑤ · wspace=⓪.①②)
ax[⓪].set_facecolor(\'None\')
ax[⓪].plot(x,y,\'o-\',color=\'gold\')
ax[⓪].set_xscale(\'log\',basex=②)
ax[⓪].set_xlim(⓪ · ④)
ax[①].set_facecolor(\'None\')
ax[①].plot(x,y,\'o-\',color=\'gold\')
ax[①].set_xlim(⓪ · ④)
ax[①].set_xscale(\'log\',basex=②)
plt.show()
③ · 左图axes.set_xbound方法在axes.invert_xaxis方法之后使用,右图axes.set_xbound方法在axes.invert_xaxis方法之前使用
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.image as img
mpl.rcParams[\'ytick.color\']=\'white\'
mpl.rcParams[\'xtick.color\']=\'white\'
mpl.rcParams[\'ytick.labelsize\']=\'large\'
mpl.rcParams[\'xtick.labelsize\']=\'large\'
mpl.rcParams[\'axes.edgecolor\']=\'white\'
x = np.linspace(⓪.⓪ · ⑤.⓪)
y = np.cos(② * np.pi * x) * np.exp(-x)
fig, ax = plt.subplots(nrows=① · ncols=②)
bgimg = img.imread(\'picture.png\')
fig.figimage(bgimg)
fig.subplots_adjust(left=⓪.⓪⑤ · right=⓪.⑨⑤ · top=⓪.⑨⑤ · bottom=⓪.⓪⑤ · wspace=⓪.①②)
ax[⓪].set_facecolor(\'None\')
ax[⓪].plot(x,y,\'o-\',color=\'gold\')
ax[⓪].invert_xaxis()
ax[⓪].set_xlim(⓪ · ④)
ax[①].set_facecolor(\'None\')
ax[①].plot(x,y,\'o-\',color=\'gold\')
ax[①].set_xlim(⓪ · ④)
ax[①].invert_xaxis()
plt.show()
④ · 左图axes.set_xlim方法在axes.invert_xaxis方法之后使用,右图axes.set_xlim方法在axes.invert_xaxis方法之前使用
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.image as img
mpl.rcParams[\'ytick.color\']=\'white\'
mpl.rcParams[\'xtick.color\']=\'white\'
mpl.rcParams[\'ytick.labelsize\']=\'large\'
mpl.rcParams[\'xtick.labelsize\']=\'large\'
mpl.rcParams[\'axes.edgecolor\']=\'white\'
x = np.linspace(⓪.⓪ · ⑤.⓪)
y = np.cos(② * np.pi * x) * np.exp(-x)
fig, ax = plt.subplots(nrows=① · ncols=②)
bgimg = img.imread(\'picture.png\')
fig.figimage(bgimg)
fig.subplots_adjust(left=⓪.⓪⑤ · right=⓪.⑨⑤ · top=⓪.⑨⑤ · bottom=⓪.⓪⑤ · wspace=⓪.①②)
ax[⓪].set_facecolor(\'None\')
ax[⓪].plot(x,y,\'o-\',color=\'gold\')
ax[⓪].invert_xaxis()
ax[⓪].set_xlim(⓪ · ④)
ax[①].set_facecolor(\'None\')
ax[①].plot(x,y,\'o-\',color=\'gold\')
ax[①].set_xlim(⓪ · ④)
ax[①].invert_xaxis()
plt.show()
编后语:关于《使用Python绘图库Matplotlib绘图时?matplotlib如何自定义显示背景》关于知识就介绍到这里,希望本站内容能让您有所收获,如有疑问可跟帖留言,值班小编第一时间回复。 下一篇内容是有关《玩英雄联盟魔兽争霸3有时在网上看视频时屏幕出现雪花?养泰迪和比熊犬谁好》,感兴趣的同学可以点击进去看看。
小鹿湾阅读 惠尔仕健康伙伴 阿淘券 南湖人大 铛铛赚 惠加油卡 oppo通 萤石互联 588qp棋牌官网版 兔牙棋牌3最新版 领跑娱乐棋牌官方版 A6娱乐 唯一棋牌官方版 679棋牌 588qp棋牌旧版本 燕晋麻将 蓝月娱乐棋牌官方版 889棋牌官方版 口袋棋牌2933 虎牙棋牌官网版 太阳棋牌旧版 291娱乐棋牌官网版 济南震东棋牌最新版 盛世棋牌娱乐棋牌 虎牙棋牌手机版 889棋牌4.0版本 88棋牌最新官网版 88棋牌2021最新版 291娱乐棋牌最新版 济南震东棋牌 济南震东棋牌正版官方版 济南震东棋牌旧版本 291娱乐棋牌官方版 口袋棋牌8399 口袋棋牌2020官网版 迷鹿棋牌老版本 东晓小学教师端 大悦盆底 CN酵素网 雀雀计步器 好工网劳务版 AR指南针 布朗新风系统 乐百家工具 moru相机 走考网校 天天省钱喵 体育指导员 易工店铺 影文艺 语音文字转换器