How can I plot a single point in Matplotlib Python?

PythonMatplotlibServer Side ProgrammingProgramming

To plot a single data point in matplotlib, we can take the following steps −

  • Initialize a list for x and y with a single value.

  • Limit X and Y axis range for 0 to 5.

  • Lay out a grid in the current line style.

  • Plot x and y using plot() method with marker="o", markeredgecolor="red", markerfacecolor="green".

  • To display the figure, use show() method.

Example

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = [4]
y = [3]
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.grid()
plt.plot(x, y, marker="o", markersize=20, markeredgecolor="red", markerfacecolor="green")
plt.show()

Output

raja
Published on 08-May-2021 09:14:29
Advertisements