I'd like to plot a single point on my graph, but it seems like they all need to plot as either a list or equation.
I need to plot like ax.plot(x, y)
and a dot will be appeared at my x
, y
coordinates on my graph.
import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import host_subplot import mpl_toolkits.axisartist as AA import numpy fig = plt.figure() plt.xlabel('Width') plt.ylabel('Height') ax = fig.gca() ax.plot(105, 200) plt.grid() plt.show()
In single-point annotation we can use matplotlib. pyplot. text and mention the x coordinate of the scatter point and y coordinate + some factor so that text can be distinctly visible from the plot, and then we have to mention the text.
To plot a line plot in Matplotlib, you use the generic plot() function from the PyPlot instance. There's no specific lineplot() function - the generic one automatically plots using lines or markers. This results in much the same line plot as before, as the values of x are inferred.
matplotlib.pyplot.scatter () is the most straightforward and standard method to plot data as points in Matplotlib. We pass the data coordinates to be plotted as arguments to the method.
matplotlib.pyplot.scatter () is the most straightforward and standard method to plot data as points in Matplotlib. We pass the data coordinates to be plotted as arguments to the method. It generates a simple scatter plot from the given data points.
By default, the plot () function draws a line from point to point. The function takes parameters for specifying points in the diagram. Parameter 1 is an array containing the points on the x-axis.
Let’s have a look at some of the basic functions that are often used in matplotlib. it creates the plot at the background of computer, it doesn’t displays it. We can also add a label as it’s argument that by what name we will call this plot – utilized in legend ()
This worked for me:
plt.plot(105,200,'ro')
matplotlib.pyplot.plot
plots y
versus x
as lines and/or markers.ax.plot(105, 200)
attempts to draw a line, but two points are required for a line plt.plot([105, 110], [200, 210])
'o'
can be used to only draw a marker. marker='o'
does not work the same as the positional argument.'ro'
specifies color and marker, respectively'-o'
or '-ro'
will draw a line and marker if two or more x
and y
values are provided.matplotlib.pyplot.scatter
can also be used to add single or multiple pointsimport matplotlib.pyplot as plt fig, ax = plt.subplots(3, 1, figsize=(8, 10)) # single point ax[0].plot(105, 110, '-ro', label='line & marker - no line because only 1 point') ax[0].plot(200, 210, 'go', label='marker only') # use this to plot a single point ax[0].plot(160, 160, label='no marker - default line - not displayed- like OP') ax[0].set(title='Markers - 1 point') ax[0].legend() # two points ax[1].plot([105, 110], [200, 210], '-ro', label='line & marker') ax[1].plot([105, 110], [195, 205], 'go', label='marker only') ax[1].plot([105, 110], [190, 200], label='no marker - default line') ax[1].set(title='Line & Markers - 2 points') ax[1].legend() # scatter plot ax[2].scatter(x=105, y=110, c='r', label='One Point') # use this to plot a single point ax[2].scatter(x=[80, 85, 90], y=[85, 90, 95], c='g', label='Multiple Points') ax[2].set(title='Single or Multiple Points with using .scatter') ax[2].legend() fig.tight_layout()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With