How to use 'vertical line matplotlib' in Python

Every line of 'vertical line matplotlib' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
93def line(data,
94 file_path,
95 style=[],
96 title='',
97 xlabel='',
98 ylabel='',
99 logx=False,
100 logy=False,
101 vlines=[]):
102 """Plots a line plot using matplotlib.
103
104 Parameters
105 ----------
106 data : pd.DataFrame
107 two column df with x and y values
108 file_path : str
109 path to save figure
110 title : str
111 graph title
112 xlabel : str
113 x-axis label
114 ylabel : str
115 y-axis label
116 vlines : list of int
117 draw vertical lines at positions
118 """
119 # plot data
120 data.plot(kind='line', style=style)
121 plt.title(title)
122 plt.xlabel(xlabel)
123 plt.ylabel(ylabel)
124
125 # log scale if neccessary
126 if logx:
127 plt.xscale('log')
128 if logy:
129 plt.yscale('log')
130
131 # plot vertical lines
132 ymin, ymax = plt.ylim() # get plotting range of y-axis
133 for l in vlines:
134 plt.vlines(l, ymin=ymin,
135 ymax=ymax,
136 color='red')
137
138 plt.tight_layout() # adjust plot margins
139 plt.savefig(file_path) # save figure
140 plt.clf() # clear figure
141 plt.close()
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets