Matplotlib ax.vlines(): Draw Vertical Lines on Plots - Guide & Examples
The ax.vlines() function is a matplotlib function that allows you to draw vertical lines on a plot. It takes parameters for the x-coordinate(s) of the line(s), the ymin and ymax values to define the height of the line(s), and additional parameters for line properties such as color, linestyle, and linewidth.\n\nHere is an example of how to use ax.vlines() function:\n\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nx = np.arange(0, 10, 0.1)\ny = np.sin(x)\n\nfig, ax = plt.subplots()\nax.plot(x, y)\n\nax.vlines(x=[2, 4, 6], ymin=-1, ymax=1, colors='r', linestyles='dashed', linewidths=2)\n\nplt.show()\n\n\nIn this example, we first generate some x and y values using numpy. We then create a figure and axis object using plt.subplots(). We plot the sine function using ax.plot(). Finally, we use ax.vlines() to draw vertical lines at x=2, 4, and 6 with ymin=-1 and ymax=1. The lines are colored red, dashed, and have a linewidth of 2.\n\nThis is just a basic example, and there are many other options and settings you can use with ax.vlines() to customize the appearance of the lines.
原文地址: https://www.cveoy.top/t/topic/pHte 著作权归作者所有。请勿转载和采集!