0% found this document useful (0 votes)
23 views4 pages

Matplotlib Usage and Examples PDF

The document provides code examples to demonstrate various matplotlib plotting capabilities including: 1) Creating simple line, scatter, and bar plots with customizable properties like colors, labels, titles, axes labels and legends. 2) Working with multiple figures and axes by creating subplots and adding text, grids, and legends. 3) Generating different chart types like line charts, histograms, bar charts and pie charts to visualize and compare data. Code shows how to customize pie chart labels, colors, explode slices, start angle and autopct labels.

Uploaded by

sstcbakchods
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Matplotlib Usage and Examples PDF

The document provides code examples to demonstrate various matplotlib plotting capabilities including: 1) Creating simple line, scatter, and bar plots with customizable properties like colors, labels, titles, axes labels and legends. 2) Working with multiple figures and axes by creating subplots and adding text, grids, and legends. 3) Generating different chart types like line charts, histograms, bar charts and pie charts to visualize and compare data. Code shows how to customize pie chart labels, colors, explode slices, start angle and autopct labels.

Uploaded by

sstcbakchods
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q1)Write programs to understand the use of Matplotlib for Simple Interactive Chart, Set the Properties of the Plot,

matplotlib and NumPy.


Answer
-import [Link] as plt
a = [1, 2, 3, 4, 5]
b = [0, 0.6, 0.2, 15, 10, 8, 16, 21]
[Link](a)

# o is for circles and r is


# for red
[Link](b, "or")

[Link](list(range(0, 22, 3)))

# naming the x-axis


[Link]('Day ->')

# naming the y-axis


[Link]('Temp ->')

c = [4, 2, 6, 8, 3, 20, 13, 15]


[Link](c, label = '4th Rep')

# get current axes command


ax = [Link]()

# get command over the individual


# boundary line of the graph body
[Link]['right'].set_visible(False)
[Link]['top'].set_visible(False)

# set the range or the bounds of


# the left boundary line to fixed range
[Link]['left'].set_bounds(-3, 40)

# set the interval by which


# the x-axis set the marks
[Link](list(range(-3, 10)))

# set the intervals by which y-axis


# set the marks
[Link](list(range(-3, 20, 3)))

# legend denotes that what color


# signifies what
[Link](['1st Rep', '2nd Rep', '3rd Rep', '4th Rep'])

# annotate command helps to write


# ON THE GRAPH any text xy denotes
# the position on the graph
[Link]('Temperature V / s Days', xy = (1.01, -2.15))

# gives a title to the Graph


[Link]('All Features Discussed')
[Link]()

Q2)Write programs to understand the use of Matplotlib for Working with Multiple Figures and Axes, Adding Text,
Adding a Grid and Adding a Legend.
import numpy as np
import [Link] as plt

# data to plot
n_groups = 5
men_means = (22, 30, 33, 30, 26)
women_means = (25, 32, 30, 35, 29)

# create plot
fig, ax = [Link]()
index = [Link](n_groups)
bar_width = 0.35
opacity = 0.8

rects1 = [Link](index, men_means, bar_width,


alpha=opacity,
color='g',
label='Men')

rects2 = [Link](index + bar_width, women_means, bar_width,


alpha=opacity,
color='r',
label='Women')

[Link]('Person')
[Link]('Scores')
[Link]('Scores by person')
[Link](index + bar_width, ('G1', 'G2', 'G3', 'G4', 'G5'))
[Link]()

plt.tight_layout()
[Link]()
Q3)Write programs to understand the use of Matplotlib for Working with Line Chart, Histogram, Bar Chart, Pie Charts.

import [Link] as plt


# Plot data
languages = 'Java', 'Python', 'PHP', 'JavaScript', 'C#', 'C++'
popuratity = [22.2, 17.6, 8.8, 8, 7.7, 6.7]
#colors = ['red', 'gold', 'yellowgreen', 'blue', 'lightcoral', 'lightskyblue']
colors = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b"]
# explode 1st slice
explode = (0.1, 0, 0, 0, 0, .1)
# Plot
[Link](popuratity, explode=explode, labels=languages, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)
[Link]("PopularitY of Programming Language\n" + "Worldwide, Oct 2017 compared to a year ago",
bbox={'facecolor':'0.8', 'pad':5})
[Link]()

You might also like