5. Interactive Line Graph using Plotly
import plotly.express as px
# Sample data
data = {
'x': [1, 2, 3, 4, 5],
'y': [2, 3, 5, 7, 11]
}
# Creating an interactive line plot
fig = px.line(data, x='x', y='y',
title='Interactive Line Graph using Plotly', markers=True)
fig.show()
4. Line Graph using Seaborn
import seaborn as sns
import matplotlib.pyplot as plt
# Sample data
data = {
'x': [1, 2, 3, 4, 5],
'y': [2, 3, 5, 7, 11]
}
# Creating a Seaborn line plot
sns.lineplot(x='x', y='y', data=data, marker='o')
plt.title('Line Graph using Seaborn')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()
3. Line Graph with Error Bars using Matplotlib
import matplotlib.pyplot as plt
import numpy as np
# Sample data
x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 3, 5, 7, 11])
yerr = np.array([0.5, 0.4, 0.3, 0.2, 0.1])
# Plotting the line graph with error bars
plt.errorbar(x, y, yerr=yerr, fmt='-o', capsize=5)
plt.title('Line Graph with Error Bars')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()
2. Multiple Line Graphs using Matplotlib
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y1 = [2, 3, 5, 7, 11]
y2 = [1, 4, 6, 8, 10]
# Plotting multiple line graphs
plt.plot(x, y1, label='Line 1', marker='o')
plt.plot(x, y2, label='Line 2', marker='s')
plt.title('Multiple Line Graphs')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
1. Basic Line Graph using Matplotlib
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# Plotting the line graph
plt.plot(x, y, marker='o')
plt.title('Basic Line Graph')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()
0 Comments:
Post a Comment