![]() Matplotlib allows the aspect ratio, DPI and figure size to be specified when. In this article, we need some basic concept of two python module named as “Matplotlib” and “Numpy”. fig, axes plt.subplots(nrows1, ncols2) for ax in axes: ax.plot(x, y. The main motto of this article is how to change or set the size of a figure in Matplotlib using Python. Setting or Changing the Size of a Figure in Matplotlib Python The matplotlib module is used to create a figure, and we can do different types of experiment with that figure such as “changing the axis of the graph”, “changing the geometric shape”, “changing the background colour of the figure” and many more. ![]() In this article, we have to only focus on changing the size of the figure. There is a method of changing the size of a figure in matplotlib by using “ figsize=(a,b)” attribute, where “a = width of the figure in unit inches” and “b = height of the figure in unit inches”. In this example we see the default drawn figure(width = height).Square size figure in Matplotlib with Python import matplotlib.pyplot as plt If we don’t use the property to change or set the size of figure, then it takes width and height both same and the result will be a square type figure. Here weve used the hspace and wspace arguments of plt.subplotsadjust, which specify the spacing along the height and width of the figure, in units of the. ![]() Now, you can see that the width and height of the figure are equal. Here, the first thing we have to do is to import two python module “ matplotlib” and “ numpy” by these line of codes:-Īnd then we created a numpy array and then established the relation between X and Y i.e. In this example again we change the width and height of the figure(width height):–.Let say we want to set the width of the figure to 2 inches and height to 6 inches. ![]() Again this change will make the figure in the shape of something like a rectangular shape. Now, you can see that the width of the figure is 1/3rd the height of the figure. The explanation is same as stated in the above examples, the only thing that is changed is the value of width and height. In this example, width = 2 inch and height = 6 inch. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |