Change matplotlib line style in mid-graph Last Updated : 12 Nov, 2020 Comments Improve Suggest changes Like Article Like Report Prerequisite: Matplotlib In this article we will learn how to change line style in mid-graph using matplotlib in Python. Matplotlib: It is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a multi-platform data visualization library built on NumPy arrays and designed to figure with the broader SciPy stack. It was introduced by John Hunter within the year 2002.Line style: Line style is a feature that describes in which fashion or style line is drawn. Following image shows the key that has to provided as input parameter and what line style it will produce: Approach: Import the matplotlib.pyplot library and other for data (optional)Import or create some dataDraw a graph plot with different line style is middle. Example 1: In this example we will use simple steps mentioned above and form a graph with two different line styles. Python3 # importing packages import matplotlib.pyplot as plt import numpy as np # create data x = np.linspace(0, 10, 100) y = 3 * x + 2 below = y < 15 above = y >= 15 # Plot lines below as dotted------- plt.plot(x[below], y[below], '--') # Plot lines above as solid________ plt.plot(x[above], y[above], '-') plt.show() Output : Example 2 : In this example we will use simple steps mentioned above and form a graph with two different line styles in one sine function. Python3 # importing packages import matplotlib.pyplot as plt import numpy as np # create data x = np.linspace(0, 10, 100) y = np.sin(x) below = y < .5 above = y >= .5 # Plot lines below as dotted------- plt.plot(x[below], y[below], '--') # Plot lines above as solid_______ plt.plot(x[above], y[above], '-') plt.show() Output : Example 3 : This is similar to above example with extra cosine function to show different feature of line styles in mid graph. Python3 # importing packages import matplotlib.pyplot as plt import numpy as np # create data x = np.linspace(0, 10, 100) y1 = np.sin(x) y2 = np.cos(x) below = abs(y1-y2) < .2 above = abs(y1-y2) >= .2 # Plot lines below as dotted------- plt.plot(x[below], y1[below], 'r--') # Plot lines below as dotted------- plt.plot(x[below], y2[below], 'g--') # Plot lines above as solid_______ plt.plot(x[above], y1[above], 'r-') # Plot lines above as solid_______ plt.plot(x[above], y2[above], 'g-') plt.show() Output : Comment More infoAdvertise with us Next Article Change matplotlib line style in mid-graph D deepanshu_rustagi Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads Change the line opacity in Matplotlib Changing Line Opacity in Matplotlib means adjusting the transparency level of a line in a plot. Opacity controls how much the background or overlapping elements are visible through the line. A fully opaque line is solid, while a more transparent line allows other elements behind it to be seen. Let's 3 min read How to Change Line Color in Matplotlib? Matlab's plotting functions are included in Python by the Inclusion of the library Matplotlib. The library allows the plotting of the data of various dimensions without ambiguity in a plot. The library is widely used in Data Science and Data visualization. In this article, we will discuss how to cha 3 min read Line plot styles in Matplotlib Line plots are important data visualization elements that can be used to identify relationships within the data. Using matplotlib.pyplot.plot() function we can plot line plots. Styling tools in this helps us customize line plots according to our requirements which helps in better representations. Li 3 min read Line chart in Matplotlib - Python Matplotlib is a data visualization library in Python. The pyplot, a sublibrary of Matplotlib, is a collection of functions that helps in creating a variety of charts. Line charts are used to represent the relation between two data X and Y on a different axis. In this article, we will learn about lin 6 min read How to Change the Line Width of a Graph Plot in Matplotlib with Python? Prerequisite : Matplotlib In this article we will learn how to Change the Line Width of a Graph Plot in Matplotlib with Python. For that one must be familiar with the given concepts: Matplotlib : Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a 2 min read Like