0% found this document useful (0 votes)
3 views3 pages

Matplotlib Advanced Commands

This document provides advanced commands for using Matplotlib, including how to change figure size, add grids, customize line styles, and add annotations. It also covers creating various types of plots such as box plots, area plots, and horizontal bar charts, as well as saving high-resolution graphs and using style sheets. Each command is illustrated with example code snippets for practical application.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Matplotlib Advanced Commands

This document provides advanced commands for using Matplotlib, including how to change figure size, add grids, customize line styles, and add annotations. It also covers creating various types of plots such as box plots, area plots, and horizontal bar charts, as well as saving high-resolution graphs and using style sheets. Each command is illustrated with example code snippets for practical application.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]()

You might also like