Python Matplotlib - Impose shape dimensions with Imsave

2024/9/16 23:20:55

I plot a great number of pictures with matplotlib in order to make video with it but when i try to make the video i saw the shape of the pictures is not the same in time...It induces some errors. Is there a command to impose the shape of the output when i use Imsave?

You can see a part of my code :

plt.close()
fig, axes = plt.subplots(nrows=2, ncols=3)###Figures composante X
plt.tight_layout(pad=0.05, w_pad=0.001, h_pad=2.0)
ax1 = plt.subplot(231) # creates first axis
ax1.set_xticks([0,2000,500,1000,1500])
ax1.set_yticks([0,2000,500,1000,1500])
ax1.tick_params(labelsize=8) 
i1 = ax1.imshow(U,cmap='hot',extent=(X.min(),2000,Y.min(),2000), vmin=U.min(), vmax=U.max())
cb1=plt.colorbar(i1,ax=ax1,ticks=[U.min(),(U.min()+U.max())/2., U.max()],fraction=0.046, pad=0.04,format='%.2f')
cb1.ax.tick_params(labelsize=8)ax1.set_title("$ \mathrm{Ux_{mes} \/ (pix)}$", y=1.05, fontsize=12)
ax2 = plt.subplot(232) # creates second axis
ax2.set_xticks([0,2000,500,1000,1500])
ax2.set_yticks([0,2000,500,1000,1500])
i2=ax2.imshow(UU,cmap='hot',extent=(X.min(),2000,Y.min(),2000), vmin=UU.min(), vmax=UU.max())
ax2.set_title("$\mathrm{Ux_{cal} \/ (pix)}$", y=1.05, fontsize=12)
ax2.set_xticklabels([])
ax2.set_yticklabels([])
cb2=plt.colorbar(i2,ax=ax2,fraction=0.046, pad=0.04,ticks=[UU.min(),(UU.min()+UU.max())/2.,UU.max()],format='%.2f')
cb2.ax.tick_params(labelsize=8)ax3 = plt.subplot(233) # creates first axis
ax3.set_xticks([0,2000,500,1000,1500])
ax3.set_yticks([0,2000,500,1000,1500])
i3 = ax3.imshow(resU,cmap='hot',extent=(X.min(),2000,Y.min(),2000),vmin=0.,vmax=0.1)
ax3.imshow(scipy.ndimage.filters.gaussian_filter(masquey2, 3),cmap='hot',alpha=0.2,extent=(X.min(),2000,Y.min(),2000))
ax3.set_title("$\mathrm{\mid \/ Ux_{mes} - Ux_{cal}\mid \/ (pix)}$ ", y=1.05, fontsize=12)
cb3=plt.colorbar(i3,ax=ax3,fraction=0.046, pad=0.04,ticks=[0.,0.1],format='%.2f')
ax3.set_xticklabels([])
ax3.set_yticklabels([])
cb3.ax.tick_params(labelsize=8)
plt.gcf().tight_layout()

I m using "plt.gcf().tight_layout()" in order to have figures which dont superimpose...

Answer

If you're saving figures out to images on disk, you can do something like this to set the size:

fig.set_size_inches(10, 15)
fig.savefig('image.png', dpi=100)

If you just want to display at a certain size you can try:

plt.figure(figsize=(1,1))

Where the dimensions are set in inches.

Here is an explanation of parameters that can be set with Figures: http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure

https://en.xdnf.cn/q/72788.html

Related Q&A

Move x-axis tick labels one position to left [duplicate]

This question already has answers here:Aligning rotated xticklabels with their respective xticks(6 answers)Closed last year.I am making a bar chart and I want to move the x-axis tick labels one positio…

PUT dictionary in dictionary in Python requests

I want to send a PUT request with the following data structure:{ body : { version: integer, file_id: string }}Here is the client code:def check_id():id = request.form[id]res = logic.is_id_valid(id)file…

Does python have header files like C/C++? [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 9 years ago.Improve…

python: Greatest common divisor (gcd) for floats, preferably in numpy

I am looking for an efficient way to determine the greatest common divisor of two floats with python. The routine should have the following layoutgcd(a, b, rtol=1e-05, atol=1e-08) """ Re…

Difference between @property and property()

Is there a difference betweenclass Example(object):def __init__(self, prop):self._prop = propdef get_prop(self):return self._propdef set_prop(self, prop):self._prop = propprop = property(get_prop, set_…

airflow webserver command fails with {filesystemcache.py:224} ERROR - Operation not permitted

I am installing airflow on a Cent OS 7. I have configured airflow db init and checked the status of the nginx server as well its working fine. But when I run the airflow webserver command I am getting …

Django REST Framework - How to return 404 error instead of 403

My API allows access (any request) to certain objects only when a user is authenticated and certain other conditions are satisfied.class SomethingViewSet(viewsets.ModelViewSet):queryset = Something.obj…

503 Reponse when trying to use python request on local website

Im trying to scrape my own site from my local server. But when I use python requests on it, it gives me a response 503. Other ordinary sites on the web work. Any reason/solution for this?import reques…

Dereferencing lists inside list in Python

When I define a list in a "generic" way:>>>a=[[]]*3 >>>a [[],[],[]]and then try to append only to the second element of the outer list:>>>a[1].append([0,1]) >>…

Unit test Theories in Python?

In a previous life I did a fair bit of Java development, and found JUnit Theories to be quite useful. Is there any similar mechanism for Python?Currently Im doing something like:def some_test(self):c…