Line plots, also known as line charts, are a type of chart used to display the trends or changes in a set of data over time. They connect the data points using straight lines and are commonly used to visualize time series data.
In Python, you can create line plots using various libraries such as Matplotlib, Seaborn, and Plotly. Here's an example using Matplotlib:
import matplotlib.pyplot as pltimport numpy as np# Generate some random datax = np.linspace(0, 10, 100)y = np.sin(x)# Create a line plotplt.plot(x, y)# Set the title and axis labelsplt.title('Line Plot of Sin(x)')plt.xlabel('x')plt.ylabel('y')# Show the plotplt.show() |
In this example, we generate 100 data points from the sine function using NumPy. We create a line plot using plt.plot(), where the first argument is the x-axis data and the second argument is the y-axis data. We then set the title and axis labels using plt.title(), plt.xlabel(), and plt.ylabel(), and display the plot using plt.show().
You can also customize the appearance of the line plot by specifying the line style, color, and other options. For example, to change the line style to dashed, add linestyle='--' to the plt.plot() call. To change the color of the line to red, add color='red'.