Surya_from_1627

ADAP6

Sep 14th, 2026
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2.  
  3. x = [1, 2, 3, 4, 5]
  4. y1 = [10, 12, 8, 14, 11]
  5. y2 = [2, 5, 7, 6, 3]
  6.  
  7. plt.plot(x, y1, label='Primary Line',
  8.          color='blue', linewidth=2)
  9. plt.plot(x, y2, label='Secondary Line',
  10.          color='red', linestyle='--')
  11.  
  12. # Adding scatter on top
  13. plt.scatter(x, y1, color='black', zorder=5)
  14.  
  15. # Adding title, legend, and grid
  16. plt.title("Layered Line and Scatter Plot")
  17. plt.xlabel("X Axis")
  18. plt.ylabel("Y Axis")
  19. plt.grid(True)
  20. plt.legend()
  21. plt.show()
  22. -------------------------------------------------------
  23. import seaborn as sns
  24. import pandas as pd
  25.  
  26. # Sample data
  27. df = pd.DataFrame({
  28.     'x': range(1, 6),
  29.     'y1': [3, 5, 7, 6, 8],
  30.     'y2': [1, 4, 2, 5, 3]
  31. })
  32.  
  33. # Base layer
  34. sns.lineplot(x='x', y='y1', data=df,
  35.              label='Line 1', color='green')
  36.  
  37. # Additional layer
  38. sns.lineplot(x='x', y='y2', data=df,
  39.              label='Line 2', color='purple',
  40.              linestyle='--')
  41.  
  42. # Annotation and customization
  43. plt.title("Seaborn Layered Line Plot")
  44. plt.grid(True)
  45. plt.legend()
  46. plt.show()
  47.  
  48. -----------------------------------------------------------
  49. plt.plot(x, y1, label='Trend', color='navy')
  50. plt.fill_between(x, y1, color='skyblue', alpha=0.3)  # shaded region layer
  51.  
  52. # Highlight a point
  53. plt.scatter([3], [8], color='red', zorder=5)
  54. plt.annotate("Peak", xy=(3, 8), xytext=(3.5, 9),
  55.              arrowprops=dict(arrowstyle='->'))
  56.  
  57. plt.title("Plot with Fill and Annotation Layers")
  58. plt.show()
  59.  
  60. -----------------------------------------------------------
  61. import plotly.graph_objects as go
  62.  
  63. fig = go.Figure()
  64.  
  65. # Layer 1: Line
  66. fig.add_trace(go.Scatter(
  67.     x=x,y=y1,mode='lines+markers', name='y1'))
  68.  
  69. # Layer 2: Line
  70. fig.add_trace(go.Scatter(
  71.     x=x, y=y2, mode='lines', name='y2'))
  72.  
  73. # Layout and Show
  74. fig.update_layout(title="Layered Plot with Plotly",
  75.                   xaxis_title="X", yaxis_title="Y")
  76. fig.show()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment