We can resize the matplotlib graphs. Actually, Matplotlib increase plot size works using figure(figsize=(length,width)). Here length and width will be in the inches. In this article, We will firstly create a simple matplotlib chart with the default size. After it, we will resize it using (figsize=(length,width)).
Matplotlib increase plot size –
We will do it into steps. In the First step, We will draw a simple chart. In the second step, we will resize it.
Step 1 : Create a simple chart –
Let’s draw the simplest chart. We will add few attributes like title, xLabel and yLabel.
import matplotlib.pyplot as plt Year = [2001,2002,2003,2004,2005] Magnitude = [100,102,145,180,101] plt.plot(Year, Magnitude) plt.title('Magnitude Vs Year') plt.xlabel('Year') plt.ylabel('Magnitude') plt.show()
It is just a line chart. Which has a default in size.
Step 2: matplotlib increase plot size-
Now we will resize the chart which we have drawn above. We will use the figsize attribute of figure package. Here we will parameterize the chart size length and width in inches. Here is the syntax for this.
from matplotlib.pyplot import figure figure( figsize=(10, 8))
Let’s fit these lines of resizing into the above example.
import matplotlib.pyplot as plt from matplotlib.pyplot import figure figure( figsize=(10, 8)) Year = [2001,2002,2003,2004,2005] Magnitude = [100,102,145,180,101] plt.plot(Year, Magnitude) plt.title('Magnitude Vs Year') plt.xlabel('Year') plt.ylabel('Magnitude') plt.show()
Now we can see the difference in the size of both the chart. The first chart with default size and other is the chart with parameterized size. I think you should use the same code and play with these parameters.
Size really matters in a different style of Visualization. Matplotlib is one of the preference in Python Libraries for Data Visualization. As we have already seen how can we resize the chart using figure module of matplotlib.pyplot. In this article, we have seen the use of figsize attribute for resizing the chart.
I hope this article must have solved the problem of resizing the Matplotlib charts. If you still have any confusion about this topic, please let us know. You may comment below in the comment box.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.