Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

Setting graph figure size

Date: 2022-12-17 14:35:31

All I want to do is make the width greater and the height smaller. I'm just doing raster plots but this question applies to any MATLAB figure. I can manually resize it using the figure directly when it's created but I want the program to spit it out in the right size to start with. 

Answers: 

The properties that can be set for a figure is referenced here.

You could then use: 

 

figure_number = 1; x = 0; % Screen position y = 0; % Screen position width = 600; % Width of figure height = 400; % Height of figure (by default in pixels) figure(figure_number, 'Position', [x y width height]);

To set the figure size in a graph using Matplotlib library in Python, you can use the figsize parameter in the Figure class. This parameter takes a tuple of width and height values in inches. For example: 

 

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(10, 5)) # width=10, height=5
ax = fig.add_subplot(111)
ax.plot([1,2,3,4], [10,20,25,30])

plt.show()

In this example, we created a figure object with width and height of 10 inches and 5 inches, respectively. The add_subplot method is used to create an axis object within the figure and then a line plot is created using the plot method. The final step is to display the plot using the show method.

You can also set the size of the plot using the set_size_inches method of the Figure class. For example: 

 

fig = plt.figure()
fig.set_size_inches(10, 5) # width=10, height=5
ax = fig.add_subplot(111)
ax.plot([1,2,3,4], [10,20,25,30])

plt.show()

In this case, the figure object is first created and then its size is set using the set_size_inches method. The rest of the steps are similar to the first example.


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com