1

I have solved Laplace's equation on an annulus with a central hole. (The blue-red colourmap part on the plot: https://i.sstatic.net/oD6mz.jpg. I would like to discard part of this plot (anything outside the black circle I've drawn onto the plot), and I want the black x I drew to be the centre of a new, smaller disk, with an off-centre hole in it that used to be a central hole in a bigger disk.

just to be clear, I want to get this: https://i.sstatic.net/oNwxG.jpg and I also wonder if it would be possible to save the values of this cropped disk in another array somehow?:

This is the closest thing to what I need that I have found so far: remove part of a plot in matplotlib however, I don't know how to implement it in my case. I feel like I should define a new mesh grid somehow, but I'm not sure how to tell it to have an off-centre hole in the plot, moreover, this does not help with saving the values of the smaller disk with the off-central hole into a new array.

This is my code for plotting the original annulus:

import numpy as np import matplotlib.pyplot as plt #initial conditions Nr = 50 N_phi = 50 radius = 10 r2 = 2 T1 = 35 T2 = 4 # define for plot r = np.linspace(r2, radius, Nr) phi = np.linspace(0, 2*np.pi, N_phi) R, phi = np.meshgrid(r, phi) X = R*np.cos(phi) Y = R*np.sin(phi) #initialise matrix T = np.ones((Nr, N_phi)) #print(np.shape(T)) #add solution to laplace's equation to matrix T for i in reversed(range(0,Nr)): T[:,i] = T1 + ((T2- T1)/np.log(r2/radius))*np.log(r[i]/radius) #plot plt.figure() yes = plt.contourf(X,Y,T,cmap='jet') plt.colorbar(yes) plt.show() 

I hope someone can guide me in the right direction. Thanks.

1 Answer 1

1

As a first start, a possibility would be to add

T = np.ma.array(T) # mask a circle in the middle: outside = np.sqrt((X + 3)**2 + (Y - 3)**2) > 5 T[outside] = np.ma.masked 

right before plt.figure(), according to https://matplotlib.org/gallery/images_contours_and_fields/contourf_demo.html#sphx-glr-gallery-images-contours-and-fields-contourf-demo-py

But I think this looks nicer if the base contourf plot is prepared with higher resolution in X and Y...

PS: e.g. setting

#initial conditions Nr = 500 N_phi = 500 

made it look quite sharp

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! I think this'll work the way I want it, it's actually not necessary to replot the unmasked thing only, as I can retrieve the values I need this way anyway.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.