How to vertically stretch graphs with matplotlib subplot [duplicate]

2024/9/20 17:35:27

With the following code, I try to plot 12 different histograms in one picture using Matplotlib.

for graph in range(1,13):name = all_results[graph-1]plt.subplot(4,3,graph, title = name)plt.tight_layout()current_model = nameplt.hist(all_val_accuracies[current_model],#range = (0.49, 0.58),bins = 50)plt.xlabel('Accuracy')plt.ylabel('Frequency')plt.axis([0.48, 0.58, 0, 50])

With this code, all histograms are plotted in one image as how I indicated it.

However, the graphs itself are squeezed to such an extend that you cant see them anymore

What can I do so that these 12 histograms are plotted in one image and that each histogram can be seen clearly?

Answer

You should be able to set the size of your plots with

matplotlib.Figure.set_size_inches

To use this you will need to save the Figure object. You can include this in your code like this :

for graph in range(1,13):name = all_results[graph-1]fig, axs = plt.subplot(4,3,graph, title = name)plt.tight_layout()current_model = nameplt.hist(all_val_accuracies[current_model],#range = (0.49, 0.58),bins = 50)fig.set_size_inches(12, 12)plt.xlabel('Accuracy')plt.ylabel('Frequency')plt.axis([0.48, 0.58, 0, 50])
https://en.xdnf.cn/q/119470.html

Related Q&A

Python Selenium Traceback (most recent call last):

Im trying to use selenium for a python web scraper but when I try to run the program I get the following error: "/Applications/Python 3.8/IDLE.app/Contents/MacOS/Python" "/Applications/P…

getting error while installing opencv via pip

python version = Python 3.8.0pip version = 19.3.1C:\Users\Sami Ullah Ch>pip3 install opencv-pythonERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)

Check whether text contains x numbers in a row [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.Improve…

How to add polling interval for a GET request in python

I have a case where I have to keep checking the response of a GET call until I see the status as success in the api response. And it takes around 20 to 50 mins to get the status from active to success.…

Total beginner wrote a tic tac toe game in Python and would like some feedback

Ive decided to learn Python about 2 weeks ago, been going through various books and videos, and Ive decided to try my hand at programming a tic tac toe game. I was somewhat successful (it doesnt recogn…

Separating tag attributes as a dictionary

My entry (The variable is of string type): <a href="https://wikipedia.org/" rel="nofollow ugc">wiki</a>My expected output: { href: https://wikipedia.org/, rel: nofollow …

How can I remove duplication of 2 separate which is interrelated with each other (PYTHON)

After reading so many title, I couldnt solved the problem below. Does anyone can help me please ? For instance, I have 2 list (list_I and list_II) which is interrelated with each other. list_I = [123,…

Array within an array?

Im trying to call up an element from an array within an array in Python. For example:array = [[a1,a2,a3,a4], [b1,b2,b3,b4], [c1,c2,c3,c4]]The question is, how would I print just the value b1?

How to create a zoned of gradation area on the edge of ROI in opencv python

I have a binary image (white and black), the where Region of Interest (ROI) is black. The shape of ROI is irregular and the location of ROI can be anywhere in the frame. I want to have a smooth gradati…