Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the necessity of plt.figure() in matplotlib?

plt.figure(figsize=(10,8))  plt.scatter(df['attacker_size'][df['year'] == 298],         # attacker size in year 298 as the y axis         df['defender_size'][df['year'] == 298],         # the marker as         marker='x',         # the color         color='b',         # the alpha         alpha=0.7,         # with size         s = 124,         # labelled this         label='Year 298') 

In the above snippet of code collected from Scatterplot in Matplotlib, what is the necessity of plt.figure()?

like image 608
Mainul Islam Avatar asked Jul 29 '16 19:07

Mainul Islam


People also ask

What does PLT figure () do?

The figure() function in pyplot module of matplotlib library is used to create a new figure.

Is PLT show () necessary?

Using plt. show() in Matplotlib mode is not required.

What is a figure in matplotlib?

figure. The figure module provides the top-level Artist , the Figure , which contains all the plot elements. The following classes are defined SubplotParams control the default spacing of the subplots Figure. Top level container for all plot elements.

What is the use of matplotlib Pyplot plot () function?

The plot() function in pyplot module of matplotlib library is used to make a 2D hexagonal binning plot of points x, y. Parameters: This method accept the following parameters that are described below: x, y: These parameter are the horizontal and vertical coordinates of the data points. x values are optional.


1 Answers

The purpose of using plt.figure() is to create a figure object.

The whole figure is regarded as the figure object. It is necessary to explicitly use plt.figure() when we want to tweak the size of the figure and when we want to add multiple Axes objects in a single figure.

# in order to modify the size fig = plt.figure(figsize=(12,8)) # adding multiple Axes objects   fig, ax_lst = plt.subplots(2, 2)  # a figure with a 2x2 grid of Axes 

Parts of a Figure

like image 104
Mainul Islam Avatar answered Sep 25 '22 01:09

Mainul Islam