Issue
I have written some code that plots the corners of a square and the center with the corrosponding value assigned to that square. The coordinates are stored as two numpy arrays in the following way:
coorCenter = np.array([[ 19.99812616, 39.9060875 ],
[-20.00187384, 39.9060875 ],
[-20.00187305, -0.10565157],
[ 19.99812695, -0.10565157],
[-19.99999842, -40.02347813],
[ 20.00000158, -40.02347813]])
coorCorner = np.array([[ 4.00000000e+01, -6.00000000e+01],
[ 4.00000000e+01, 6.00000000e+01],
[ 4.00000000e+01, -2.00000000e+01],
[ 4.00000000e+01, 2.00000000e+01],
[-4.00000000e+01, 6.00000000e+01],
[ 6.93889390e-15, 6.00000000e+01],
[-4.00000000e+01, -6.00000000e+01],
[-4.00000000e+01, 2.00000000e+01],
[-4.00000000e+01, -2.00000000e+01],
[ 6.93889390e-15, -6.00000000e+01],
[-5.62152798e-03, 1.97182625e+01],
[ 4.75348769e-06, -2.00704344e+01]])
Values = [0.00308649, -0.00308693, -0.03431792, 0.03431309, 0.1164378, -0.11643781]
My current code is as follows but I have troubles adding a title and axis labels
import numpy as np
from matplotlib import pyplot
from Assembly import AssembleCenterCoordinates
def centerPlot(G, A, Values, axis_size):
coorCenter = AssembleCenterCoordinates(G, A)
coorCorner = G.get('coor')
# round numbers to 2 decimal points
Values = [np.format_float_positional(Values[i], precision=2) for i in range(len(Values))]
fig = pyplot.figure()
ax = fig.add_subplot(111)
ax.set_ylim(-axis_size,axis_size)
ax.set_xlim(-axis_size,axis_size)
ax.set_aspect('equal', adjustable='box')
pyplot.scatter(coorCenter[:,0],coorCenter[:,1])
pyplot.scatter(coorCorner[:,0],coorCorner[:,1])
for i,j,k in zip(coorCenter[:,0],coorCenter[:,1],Values):
# annotating our points and offsetting the text
ax.annotate(str(k), xy=(i,j), xytext=(5,5), textcoords='offset points')
pyplot.show()
Here is how my current plot looks: https://i.imgur.com/RqVPkRJ.png
And here is how I would like it to look: https://i.imgur.com/5EKmQnS.png
Solution
Just before pyplot.show()
, add these lines:
pyplot.title('Title here')
pyplot.xlabel('X-Label')
pyplot.ylabel('Y-Label')
Answered By - The Thonnu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.