Trusted answers to developer questions

Fouzia Bashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

**Matplotlib** is used to visualize statistical data for clear and concise understanding. It makes complicated data coherent with the aid of different graphs and plots.

A graph is used to classify data as leaf and step. It has a baseline with heads moving outwards away from the baseline.

`Matplotlib.pyplot.stem()`

methodThe `stem()`

** method** of the `matplotlib.pyplot`

API is used to create a stem plot. It can be plotted in two ways either vertically or horizontally.

For the horizontal stem plot, `locs`

are x positions while the `heads`

are y values.

For the vertical stem plot, `locs`

are y positions while the `heads`

are x values.

matplotlib.pyplot.stem(locs, heads, linefmt=None, markerfmt=None, basefmt=None)

`locs`

: For the horizontal plot, these are y-positions of the stem. On the other hand, for a vertical plot, these value shows the x-position of the stem.`heads`

: For the horizontal plot, these are x-values of stem heads. On the other hand, for a vertical plot, these value shows the y-values of stem heads.`linefmt`

: This string value defines the color and style of vertical lines.`marketfmt`

: This string value defines the color and style of markers.`basefmt`

: This is a format for the baseline.

This method returns a tuple of marker lines, stemlines, and baselines.

# import libraries in program import matplotlib.pyplot as plt import numpy as np # generate x values x = np.linspace(1, 2** np.pi) # generate y values. y = np.exp(np.cos(x)) # invoking stem() method plt.stem(x, y, linefmt ='red', markerfmt ='-.', bottom = 1.1, use_line_collection = True) # save above generated plot as png image in root directory plt.savefig('output/graph.png')

- Lines 2 and 3: We import the
`matplotlib.pyplot`

API as`plt`

and NumPy as`np`

. - Line 5: We use the
`np.linspace()`

method that generates 50 sample ranges between`1`

and`8.824977827076287`

. - Line 7: We calculate the exponent of
`np.cos(x)`

values and return a list of 50 samples,`x`

. - Line 9: We pass the following parameters to the
`stem`

method: `locs`

and`heads`

as a list of 50 values.`linefmt`

indicates lines will be`red`

in color.`markerfmt`

shows the style of the marker.`use_line_collection`

is set to`True`

, which means it will first use lines collection and then individual lines- Line 11: We use the
`plt.savefig()`

method to save the output graph as a`graph.png`

file.

RELATED TAGS

python

CONTRIBUTOR

Fouzia Bashir

Grokking Modern System Design Interview for Engineers & Managers

Keep Exploring

Related Courses