我的情节中的标记距离图像中的位置很远
我有以下代码,该代码绘制了一个普通的plt.plot,每个值都在每个值中绘制标记,但是标记文本远离图像中的标记点。我能做什么?这取决于图的大小吗?因为我也尝试了不同的数字尺寸。
import matplotlib.pyplot as plt
df.reset_index(inplace=True)
f = plt.figure()
f.set_figwidth(10)
f.set_figheight(8)
x = df["State"]
y = df["Total revenue"]
def add_value_label(x_list,y_list):
for i in range(1, len(x_list)+1):
plt.text(i,y_list[i-1],y_list[i-1])
add_value_label(x, y)
plt.plot(x, y, marker='o',color ='orange',markerfacecolor='orange',markeredgecolor='orange')
plt.show()
I have the following code, which plots a normal plt.plot with markers in each value, however the markers text is far away from the marker point as seen in the image. Is there something I can do? Does it depends in the figure size? because I also tried with different figure sizes.
import matplotlib.pyplot as plt
df.reset_index(inplace=True)
f = plt.figure()
f.set_figwidth(10)
f.set_figheight(8)
x = df["State"]
y = df["Total revenue"]
def add_value_label(x_list,y_list):
for i in range(1, len(x_list)+1):
plt.text(i,y_list[i-1],y_list[i-1])
add_value_label(x, y)
plt.plot(x, y, marker='o',color ='orange',markerfacecolor='orange',markeredgecolor='orange')
plt.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在计算从1的x值和0的y值。您可以在图中看到,这些值是正确的,但是它们将一个X列移到右侧。
You're counting your X values from 1 and your Y values from 0. You can see that in the plot -- the values are right, but they're shifted one x column to the right.