Matplotlib Advanced Commands
1. Change Figure Size
[Link](figsize=(8, 5))
[Link]([1, 2, 3], [4, 5, 6])
[Link]()
2. Add Grid
[Link]([1, 2, 3], [1, 4, 9])
[Link](True)
[Link]()
3. Change Line Style, Width, and Color
[Link]([1, 2, 3], [2, 4, 6], color='purple', linestyle='--', linewidth=2)
[Link]()
4. Add Marker Styles
[Link]([1,2,3], [3,2,5], marker='o', color='orange', linestyle='--', markersize=8)
[Link]()
5. Add Text or Annotations
[Link]([1, 2, 3], [2, 4, 6])
[Link](2, 4, 'Midpoint', fontsize=12, color='red')
[Link]()
[Link]('Peak', xy=(3, 6), xytext=(2, 7), arrowprops=dict(facecolor='black', arrowstyle='->'))
[Link]()
6. Axis Range and Scale
[Link]([1, 2, 3, 4], [2, 4, 8, 16])
[Link](0, 5)
[Link](0, 20)
[Link]()
7. Axis Labels Rotation
[Link](['Python', 'Java', 'C++', 'C#'], [85, 75, 60, 50])
[Link](rotation=45)
[Link]()
8. Custom Titles and Labels
[Link]('Sales Data', fontsize=16, color='blue', fontweight='bold')
[Link]('Months', fontsize=12)
[Link]('Revenue', fontsize=12)
[Link]()
9. Change Background Color
[Link](facecolor='lightyellow')
[Link]([1, 2, 3], [3, 6, 9])
[Link]()
10. Legends with Position
[Link]([1,2,3], [1,4,9], label='Squares')
[Link]([1,2,3], [1,2,3], label='Line')
[Link](loc='upper left')
[Link]()
11. Box Plot
import numpy as np
data = [Link](100)
[Link](data)
[Link]('Box Plot Example')
[Link]()
12. Area Plot
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 6, 7]
plt.fill_between(x, y, color='skyblue', alpha=0.5)
[Link]('Area Plot Example')
[Link]()
13. Stack Plot
days = [1, 2, 3, 4, 5]
sleeping = [7, 8, 6, 11, 7]
eating = [2, 3, 4, 3, 2]
working = [7, 8, 7, 2, 2]
playing = [8, 5, 7, 8, 13]
[Link](days, sleeping, eating, working, playing, labels=['Sleeping', 'Eating', 'Working',
'Playing'])
[Link]()
[Link]('Stack Plot Example')
[Link]()
14. Horizontal Bar Chart
[Link](['Python', 'Java', 'C++'], [90, 70, 50], color='teal')
[Link]('Horizontal Bar Chart')
[Link]()
15. Display Image using Matplotlib
import [Link] as mpimg
img = [Link]('[Link]')
[Link](img)
[Link]('off')
[Link]()
16. Save High-Resolution Graph
[Link]([1, 2, 3], [3, 6, 9])
[Link]('high_quality_plot.png', dpi=300, bbox_inches='tight')
17. Use Style Sheets
[Link]('ggplot')
[Link]([1,2,3], [2,4,6])
[Link]()