Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- x = [1, 2, 3, 4, 5]
- y1 = [10, 12, 8, 14, 11]
- y2 = [2, 5, 7, 6, 3]
- plt.plot(x, y1, label='Primary Line',
- color='blue', linewidth=2)
- plt.plot(x, y2, label='Secondary Line',
- color='red', linestyle='--')
- # Adding scatter on top
- plt.scatter(x, y1, color='black', zorder=5)
- # Adding title, legend, and grid
- plt.title("Layered Line and Scatter Plot")
- plt.xlabel("X Axis")
- plt.ylabel("Y Axis")
- plt.grid(True)
- plt.legend()
- plt.show()
- -------------------------------------------------------
- import seaborn as sns
- import pandas as pd
- # Sample data
- df = pd.DataFrame({
- 'x': range(1, 6),
- 'y1': [3, 5, 7, 6, 8],
- 'y2': [1, 4, 2, 5, 3]
- })
- # Base layer
- sns.lineplot(x='x', y='y1', data=df,
- label='Line 1', color='green')
- # Additional layer
- sns.lineplot(x='x', y='y2', data=df,
- label='Line 2', color='purple',
- linestyle='--')
- # Annotation and customization
- plt.title("Seaborn Layered Line Plot")
- plt.grid(True)
- plt.legend()
- plt.show()
- -----------------------------------------------------------
- plt.plot(x, y1, label='Trend', color='navy')
- plt.fill_between(x, y1, color='skyblue', alpha=0.3) # shaded region layer
- # Highlight a point
- plt.scatter([3], [8], color='red', zorder=5)
- plt.annotate("Peak", xy=(3, 8), xytext=(3.5, 9),
- arrowprops=dict(arrowstyle='->'))
- plt.title("Plot with Fill and Annotation Layers")
- plt.show()
- -----------------------------------------------------------
- import plotly.graph_objects as go
- fig = go.Figure()
- # Layer 1: Line
- fig.add_trace(go.Scatter(
- x=x,y=y1,mode='lines+markers', name='y1'))
- # Layer 2: Line
- fig.add_trace(go.Scatter(
- x=x, y=y2, mode='lines', name='y2'))
- # Layout and Show
- fig.update_layout(title="Layered Plot with Plotly",
- xaxis_title="X", yaxis_title="Y")
- fig.show()
Advertisement
Add Comment
Please, Sign In to add comment