📜  Python中的 Matplotlib.pyplot.axvline()

📅  最后修改于: 2022-05-13 01:54:54.648000             🧑  作者: Mango

Python中的 Matplotlib.pyplot.axvline()

Matplotlib是一个绘图库,用于在Python中创建静态、动画和交互式可视化。 Matplotlib 可用于Python脚本、 Python和 IPython shell、Web 应用程序服务器以及各种图形用户界面工具包,如 Tkinter、awxPython 等。

注意:有关更多信息,请参阅Python Matplotlib - 概述

Pyplot是一个 Matplotlib 模块,它提供了一个类似 MATLAB 的接口。 Matplotlib 旨在与 MATLAB 一样可用,具有使用Python的能力以及免费和开源的优势。

注意:更多信息请参考 Matplotlib 中的 Pyplot

matplotlib.pyplot.axvline()

此函数在绘图的轴上添加垂直线

示例 1:

# Importing matplotlib.pyplot as plt
import matplotlib.pyplot as plt
  
  
# Initialising values of x and y
x =[0, 5, 10, 15, 20]
y =[1, 3, 5, 6, 9]
  
# Plotting the graph
plt.plot(x, y)
  
# Drawing red vertical line at
# x = 2.5 starting at half the 
#length of y axis(ymin = 0.5) and 
#continuing till the end(ymax = 1)
# And setting the color of line to red
plt.axvline(x = 2.5, ymin = 0.5, ymax = 1,
            color ='red')
  
plt.show()

输出 :
Matplotlib.pyplot.axvline

示例 2:

import matplotlib.pyplot as plt
  
x =[0, 5, 10, 15, 20]
y =[1, 3, 5, 6, 9]
  
plt.plot(x, y)
# Drawing vertical line from 25 % 
# of the y-axis length to 80 % 
# And also increasing the linewidth
plt.axvline(x = 2.5, ymin = 0.25, ymax = 0.80,
            linewidth = 8, color ='green')
  
plt.show()

输出:
Matplotlib.pyplot.axvline

示例 3:

import matplotlib.pyplot as plt
  
x =[0, 5, 10, 15, 20]
y =[1, 3, 5, 6, 9]
  
plt.plot(x, y)
  
# Drawing vertical line from 25 %
# of the y-axis length to 75 % 
# And also changing the linestyle
plt.axvline(x = 2.5, ymin = 0.25, ymax = 0.75,
            linewidth = 4, linestyle ="--",
            color ='red')
  
plt.show()

输出:
Matplotlib.pyplot.axvline