To plot one 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 current line style. Plot given x and y using plot() method, with marker="o", markeredgecolor="red", markerfacecolor="green". To
display the figure, use show() method.
Examplefrom 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 Updated on 06-May-2021 13:35:43
- Related Questions & Answers
- How can I plot a single point in Matplotlib Python?
- How to plot a line in Matplotlib with an interval at each data point?
- How to plot single data with two Y-axes (two units) in Matplotlib?
- How to plot a point on 3D axes in Matplotlib?
- How to extract data from a Matplotlib
plot?
- How to merge two existing Matplotlib plots into one plot?
- How to plot multiple horizontal bars in one chart with matplotlib?
- How to plot a single line in Matplotlib that continuously changes color?
- How to plot a line graph from histogram data in Matplotlib?
- How to plot data into imshow() with custom colormap in Matplotlib?
- How to plot true/false or active/deactive data in Matplotlib?
- How to plot CSV data using Matplotlib and Pandas in Python?
- Plot multiple time-series DataFrames into a single plot using Pandas (Matplotlib)
- How to plot matplotlib contour?
- How to plot pie-chart with a single pie highlighted with Python Matplotlib?
matplotlib.pyplot.plot and matplotlib.axes.Axes.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 and matplotlib.axes.Axes.scatter can also be used to add single or multiple points- Tested in
python 3.10 , matplotlib 3.5.1 , seaborn 0.11.2
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()
Seabornseaborn is a high-level api for matplotlib , and offers additional options for plotting single points.sns.lineplot and sns.scatterplot are axes-level plots. sns.lineplot has keyword arguments, which are passed to matplotlib.axes.Axes.plot sns.scatterplot has
keyword arguments, which are passed to matplotlib.axes.Axes.scatter
sns.relplot is a figure-level plot, with a kind= parameter. kind='line' passes to sns.lineplot kind='scatter' passes to sns.scatterplot
x= and y= must be passed
as a vector in the following cases.
axes-level plotssns.lineplot(x=[1], y=[1], marker='o', markersize=10, color='r')
sns.scatterplot(x=[1], y=[1], s=100, color='r')
sns.relplot(kind='line', x=[1], y=[1], marker='o', markersize=10, color='r')
sns.relplot(kind='scatter', x=[1], y=[1], s=100, color='r')
How do you plot a single value?
MatPlotLib with Python. 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 current line style.. Plot given x and y using plot() method, with marker="o", markeredgecolor="red", markerfacecolor="green".. To display the figure, use show() method..
How do you show a value in a plot in Python?
Just call the plot() function and provide your x and y values. Calling the show() function outputs the plot visually.
How do you label a single point in a matplotlib graph in Python?
annotate() to label a single point. Call matplotlib. pyplot. annotate(s, xy) to add a label string s to a point, where xy is a tuple of the point coordinates.
How do I plot data in Python?
Data can also be plotted by calling the matplotlib plot function directly.. The command is plt.plot(x, y). The color and format of markers can also be specified as an additional optional argument e.g., b- is a blue line, g-- is a green dashed line..
|