Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a single point in matplotlib

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() 

enter image description here

like image 654
Xrypto Avatar asked Feb 13 '15 16:02

Xrypto


People also ask

How do you label a single point in a matplotlib graph in Python?

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.

How do I plot a line in matplotlib?

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.

How to plot data as points in Matplotlib?

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.

How do I plot a scatter plot in Matplotlib?

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.

How does the plot () function work in Python?

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.

What are the basic functions used in Matplotlib?

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 ()


2 Answers

This worked for me:

plt.plot(105,200,'ro')  
like image 52
scottlittle Avatar answered Sep 20 '22 15:09

scottlittle


  • 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])
  • A third positional argument consists of line type, color, and/or marker
    • 'o' can be used to only draw a marker.
      • Specifying 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 points
import 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() 

enter image description here

like image 25
Trenton McKinney Avatar answered Sep 21 '22 15:09

Trenton McKinney