matplotlib scatter title

matplotlib scatter title

To add a title and axis labels, you can use the set_title method of the Axes object (ax) and the set_xlabel and set_ylabel methods. Here's an updated version of your code:

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')
 
 # Add title and axis labels
 ax.set_title('Center Plot')
 ax.set_xlabel('X Axis')
 ax.set_ylabel('Y Axis')
 
 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()

This will add a title "Center Plot" and axis labels "X Axis" and "Y Axis" to your plot.