Xry*_*pto 22 python matplotlib
我想在我的图表上绘制一个点,但似乎他们都需要绘制为列表或方程式.
我需要绘制像ax.plot(x,y)的图,并且我的图上的x,y坐标上会出现一个点.
这是我的代码
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.set_xticks(numpy.arange(0,grid[0] + 20,20))
ax.set_yticks(numpy.arange(0,grid[1] + 20,20))
ax.plot(105, 200)
plt.grid()
plt.show()
Run Code Online (Sandbox Code Playgroud)
Tre*_*ney 25
matplotlib.pyplot.plot和matplotlib.axes.Axes.plot绘图与线条和/或标记y的比较x。ax.plot(105, 200)尝试画一条线,但线需要两个点
plt.plot([105, 110], [200, 210])'o'只能用于绘制标记。
marker='o'作用与位置参数的作用不同。'ro'分别指定颜色和标记'-o'如果提供了两个或多个和值,或'-ro'将绘制一条线和标记。xymatplotlib.pyplot.scatter也matplotlib.axes.Axes.scatter可用于添加单个或多个点python 3.10, matplotlib 3.5.1,seaborn 0.11.2import matplotlib.pyplot as plt
fig, ax = plt.subplots(3, 1, figsize=(8, 10), tight_layout=True)
# 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()
Run Code Online (Sandbox Code Playgroud)
seaborn是 的高级 api matplotlib,并提供用于绘制单点的附加选项。sns.lineplot和sns.scatterplot是轴级图。
sns.lineplot有关键字参数,这些参数被传递给matplotlib.axes.Axes.plotsns.scatterplot有关键字参数,这些参数被传递给matplotlib.axes.Axes.scattersns.relplot是带有参数的图形级图kind=。
kind='line'传递到sns.lineplotkind='scatter'传递到sns.scatterplotx=在以下情况下必须y=作为向量传递。sns.lineplot(x=[1], y=[1], marker='o', markersize=10, color='r')
Run Code Online (Sandbox Code Playgroud)
sns.scatterplot(x=[1], y=[1], s=100, color='r')
Run Code Online (Sandbox Code Playgroud)
sns.relplot(kind='line', x=[1], y=[1], marker='o', markersize=10, color='r')
Run Code Online (Sandbox Code Playgroud)
sns.relplot(kind='scatter', x=[1], y=[1], s=100, color='r')
Run Code Online (Sandbox Code Playgroud)
sco*_*tle 22
这对我有用:
plt.plot(105,200,'ro')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26144 次 |
| 最近记录: |