Plot variation along x and y axis

Hi everyone,i wrote code for a project,my problem is that i can’t plot the solution data with x axis and y axis,i mean plot(x,data),plot(y,data) and plot(t,data). thanks any suggestion will save me a lot and will be thanked

from dolfin import *
import numpy as np
import matplotlib.pyplot as plt
tol = 1.0e-14
dt=1
NumSteps =4
l=145
h=45
nx = ny = 6
# la maille ,plaque pour longueur l=145 ET hauteur h=45
mesh =RectangleMesh(Point(0, 0), Point(145, 45), nx, ny,'left')
#espace de fonction,ici polynome de lagrange (p)et la maille (mesh) et dégré 1
V = FunctionSpace(mesh, 'P', 1)
m=mesh.cells()
print("coordonné",m)
#boundary_markers= MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
def BoundaryTo(x,on_boundary):#condition initial de dirichlet t=o
     #dirichlet T0
    return on_boundary
bTo= AutoSubDomain(BoundaryTo)
#bTo.mark(boundary_markers,0)
#newmanxo
def Boundaryxo(x,on_boundary):#condition neumann pour x=o
    return on_boundary and abs(x[0])<tol
bxo= AutoSubDomain(Boundaryxo)
#bxo.mark(boundary_markers,1)
#newmanyo
def Boundaryyo(x,on_boundary):#codition neumann pour y=o
    return on_boundary and abs(x[1])<tol
byo= AutoSubDomain(Boundaryyo)
#byo.mark(boundary_markers,2)

def Boundaryxl(x,on_boundary):#condition neumann pour x=l
    return on_boundary and abs(x[1]-l)<tol
bxl= AutoSubDomain(Boundaryxl)
#bxl.mark(boundary_markers,3)
#newmanyh
def Boundaryyh(x,on_boundary):# condition neumann pour y=h
    return on_boundary and abs(x[1]-h)<tol
byh= AutoSubDomain(Boundaryyh)
#byh.mark(boundary_markers,4)
boundary_markers= MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundary_markers.set_all(5)#pour marker et attribuer le numéro a chaque sous domaine
#bTo=BoundaryTo()
bTo.mark(boundary_markers,0)
#bxo=Boundaryxo()
bxo.mark(boundary_markers,1)
#byo=Boundaryyo()
byo.mark(boundary_markers,2)
#bxl=Boundaryxl()
bxl.mark(boundary_markers,3)
#byh=Boundaryyh()
byh.mark(boundary_markers,4)


T0= Expression(('20.0'), degree=0)#valeur de T0 À t=o
q_1 = Expression(('397.0'), degree=0)#valeur de q_1 pour x=o
q_2 = Expression(('0.0'), degree=0)#pour y=o
q_3 = Expression(('0.0'), degree=0)#pour x=l
q_4 = Expression(('0.0'), degree=0)#pour y=h

# mettre a jour les tempÉ test et essai dans le domaine V avec u=T
u = TrialFunction(V)
v = TestFunction(V)
#METTRE a jour les tempé lorque t varie ici un=Tn et u1=Tn+1
un = Function(V)
u1 = Function(V)
pp0 = interpolate(T0, V)#on ve calculé la valeur de 'un' et u1 pour chaque projection de T0
un.assign(pp0)#ici 'un' a t=0 'un=pp0'
u1.assign(pp0)#idem u1=pp0 a t=0

#dictionnaire des condiction aux limites avec numéro de leurs mark et leurs valeur
boundary_conditions = {0: {'bTo': T0},
                       1: {'bxo': q_1},
                       2: {'byo': q_2},
                       3: {'bxl':q_3},
                       4: {'byh':q_4}}
 #on ve collecter neumann condition et direchlet condition basé sou boundary_condition
bcs = []
integrals_N = []
ds=Measure("ds",subdomain_data=boundary_markers)
for i in boundary_conditions:
    if 'bTo' in boundary_conditions[i]:
        bcs.append(DirichletBC(V, T0, boundary_markers, i))

# Build constant power heat source on surface
for i in boundary_conditions:
    if 'bxo' in boundary_conditions[i]:
        q_1 = boundary_conditions[i]['bxo']
        bb_1 = v * q_1 * ds(i)
        integrals_N.append(bb_1)
for i in boundary_conditions:
    if 'byo' in boundary_conditions[i]:
        q_2 = boundary_conditions[i]['byo']
        bb_2 = v * q_2 * ds(i)
        integrals_N.append(bb_2)
for i in boundary_conditions:
    if 'bxl' in boundary_conditions[i]:
        q_3 = boundary_conditions[i]['bxl']
        bb_3 = v * q_3 * ds(i)
        integrals_N.append(bb_3)
for i in boundary_conditions:
    if 'byh' in boundary_conditions[i]:
        q_4 = boundary_conditions[i]['byh']
        bb_4 = v * q_4 * ds(i)
        integrals_N.append(bb_4)




#k et p_c valeur
K = 0.45
p_c=1.74e6
#la  formulation de la solution a résoudre sous forme a(u,v)=l(v)
a = (dt * K * inner(grad(v), grad(u)) + p_c*v * u) * dx
L = dt * sum(integrals_N) + p_c*v*un*dx

#vdim = u1.vector().array()
#print ('Solution vector size = ',vdim)

#créer un fichier vtkfile pour visualiser la solution sur paraview
vtkfile = File('grand/grand_solution.pvd')

# mettre a jour la variation du t pour la résolution finale
t = 0
for nn in range(NumSteps):#condition pour nn dans 0 à numsteps=4
       
    t += dt#lorsque t varie de dt ,t pend t+dt
    #Solve
  
    solve(a == L, u1, bcs)#resoudre ,u1=[n_i]u_i avec n_i polynome de lagrange et u_i valeus sur les noeud 
    #Update solution
    un.assign(u1)#mise à jour de u1
    vtkfile << (u1, t)#sauvégardé u1 et t dans vtkfile pour la visualisation sur paraview
    plot(u1)#construire u1
    data=u1.vector().get_local()# avoir u1 sous forme python tableau
    print('donné de u1=',data)#affiché
   
#motrer le plot et quité
plt.show()#montrer la figuire

Dear @dadd_dadesso,
I would strongly recommend you to write your questions in english, as most people on the forum are not french.

I’ve made some changes to your question, by adding the appropriate formatting.
However, I would suggest that you try to reduce the problem to a minimal code example, as it is not clear what your problem is, and the code seems rather lengthy to relate to a plotting issue.

1 Like

“”“hello dokken, thank you very much, by the way I want to plot the final solution “u1” of the heat equation, according to the axes, my solution depends on time, on the x and y axis , as a function of time too , i.e. plot(x,u1) ,plot(y,u1)
plot(t,u1)
;thank you very much for your support, for storing the code for me”"""
from dolfin import *
import numpy as np
import matplotlib.pyplot as plt
tol = 1.0e-14
dt=1
NumSteps =4
l=145
h=45
nx = ny = 6

la maille ,plaque pour longueur l=145 ET hauteur h=45

mesh =RectangleMesh(Point(0, 0), Point(145, 45), nx, ny,‘left’)
#espace de fonction,ici polynome de lagrange (p)et la maille (mesh) et dégré 1
V = FunctionSpace(mesh, ‘P’, 1)
m=mesh.cells()
print(“coordonné”,m)
solve(a == L, u1, bcs)#solver

Please do not put the question in the title of your post.

Please also use markdown syntax to encapsulate code (3x` encapsulation), as I illustrated when I first edited your code.

Please note that I would strongly suggest using external software, such as Paraview to plot over lines of your problem.

ok thank you, I am a beginner in python, I have not yet mastered paraview well, as you just said, I will go to master it, thank you for your quick help, it enlightened me a lot of things