我写了一些代码,用对应的值来绘制正方形的角和中心,坐标以如下方式存储为两个numpy数组:
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]
我当前的代码如下所示,但是在添加标题和轴标签时遇到了麻烦
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()
以下是我当前打印的外观:https://i.imgur.com/RqVPkRJ.png
下面是我希望它看起来的样子:https://i.imgur.com/5EKmQnS.png
1条答案
按热度按时间mwg9r5ms1#
在
pyplot.show()
之前添加以下行: