我怎样才能在坐标轴上绘图
how can I plot on the axes
我实际上想重新创建如下图像:
特别是 xaxes 上的小 X
我有一个
list = [[100,-3],[200,None],[120,-2] ... ]
我也是
for x in list:
if x[1]!=None:
plot(x[0],x[1],'ok')
else:
### PLot on the axes ###
但是我在绘图时不知道坐标轴是什么。我知道有些值是 None,例如(250,None),所以我想在 x = 250 处绘制 xaxes,但我不知道最终 min(ylim() ) 将是。
我知道我可以做到 plot(250,-5,'X',zorder=999999)
但这只有当我知道最小轴是什么时..(我不能做最小、最大等来知道最小轴。因为真实数据是字典中列表中的列表等.. )
您可以使用 clip_on = False
选项。示例:
对于您的情况,您可以设置 y 限制。
示例:
x = [0,1,2,3,4,5]
y = [0,0,0,0,0,0]
plt.plot(x,y,'x',markersize=20,clip_on=False,zorder=100)
plt.ylim(0,1)
plt.show()
您可以使用 get_ylim()
来获取轴的位置,然后在其上绘图。
所以诀窍是使用自定义转换。 x 轴的常规数据转换和 y 轴的轴转换。 Matplotlib 将其称为混合转换,您需要自己创建。您将在 awesome guide 中找到更多信息。
正如@ThePredator 已经指出的那样,您必须设置 clip_on=False
,否则您的标记将被剪裁。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as transforms
fig, ax = plt.subplots()
# the x coords of this transformation are data, and the
# y coord are axes
trans = transforms.blended_transform_factory( ax.transData, ax.transAxes)
# data points on the axes
x = np.random.rand(5)*100. + 200.
y = [0]*5
ax.plot(x, y, 'kx', transform=trans, markersize=10, markeredgewidth=2,
clip_on=False)
# regular data
x = np.random.rand(5)*100. + 200.
y = np.random.rand(5)*100. + 200.
ax.plot(x, y, 'ro')
plt.show()
结果:
我实际上想重新创建如下图像:
特别是 xaxes 上的小 X 我有一个
list = [[100,-3],[200,None],[120,-2] ... ]
我也是
for x in list:
if x[1]!=None:
plot(x[0],x[1],'ok')
else:
### PLot on the axes ###
但是我在绘图时不知道坐标轴是什么。我知道有些值是 None,例如(250,None),所以我想在 x = 250 处绘制 xaxes,但我不知道最终 min(ylim() ) 将是。
我知道我可以做到 plot(250,-5,'X',zorder=999999)
但这只有当我知道最小轴是什么时..(我不能做最小、最大等来知道最小轴。因为真实数据是字典中列表中的列表等.. )
您可以使用 clip_on = False
选项。示例:
对于您的情况,您可以设置 y 限制。
示例:
x = [0,1,2,3,4,5]
y = [0,0,0,0,0,0]
plt.plot(x,y,'x',markersize=20,clip_on=False,zorder=100)
plt.ylim(0,1)
plt.show()
您可以使用 get_ylim()
来获取轴的位置,然后在其上绘图。
所以诀窍是使用自定义转换。 x 轴的常规数据转换和 y 轴的轴转换。 Matplotlib 将其称为混合转换,您需要自己创建。您将在 awesome guide 中找到更多信息。
正如@ThePredator 已经指出的那样,您必须设置 clip_on=False
,否则您的标记将被剪裁。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as transforms
fig, ax = plt.subplots()
# the x coords of this transformation are data, and the
# y coord are axes
trans = transforms.blended_transform_factory( ax.transData, ax.transAxes)
# data points on the axes
x = np.random.rand(5)*100. + 200.
y = [0]*5
ax.plot(x, y, 'kx', transform=trans, markersize=10, markeredgewidth=2,
clip_on=False)
# regular data
x = np.random.rand(5)*100. + 200.
y = np.random.rand(5)*100. + 200.
ax.plot(x, y, 'ro')
plt.show()
结果: