Python | Figure Size of Plot

Python | Figure Size of Plot: In this article, we are going to learn about the figure size of plot and its Python implementation.
Submitted by Anuj Singh, on July 13, 2020

In some cases, the automatic figure size generated by the matplotlib.pyplot is not visually good or there could be some non-acceptable ratio in the figure. So, rather than allowing a pyplot to decide the figure size, we can manually define the dimensions of the figure.

In this article, we are going to change figure size using an inbuilt function:

matplotlib.pyplot.figure(figsize)

Syntax:

matplotlib.pyplot.figure(figsize=(9,3))

# figsize(float, float)
    width, height in inches.

1) Wide Figure

Python | Figure Size of Plot (1)

2) Tall Plot

Python | Figure Size of Plot (2)

3) Small Square Figure

Python | Figure Size of Plot (3)

4) Square Figure

Python | Figure Size of Plot (4)

Python code for figure size of plot

# Data Visualization using Python
# Figure Size

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(50)
y = 2*x*x + 7*x - 14

# Example 1 
plt.figure(figsize=(9,5))
# Leftmost
plt.plot(x, y, 'yo')
plt.title('Plot')
plt.ylabel('Function Vaule')
plt.xlabel('x-axis')
plt.show()

# Example 2 
plt.figure(figsize=(6,9))
# Leftmost
plt.plot(x, y, 'yo')
plt.title('Plot')
plt.ylabel('Function Vaule')
plt.xlabel('x-axis')
plt.show()

# Example 3
plt.figure(figsize=(3,3))
# Leftmost
plt.plot(x, y, 'yo')
plt.title('Plot')
plt.ylabel('Function Vaule')
plt.xlabel('x-axis')
plt.show()

# Example 4 
plt.figure(figsize=(7,7))
# Leftmost
plt.plot(x, y, 'yo')
plt.title('Plot')
plt.ylabel('Function Vaule')
plt.xlabel('x-axis')
plt.show()

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.