图未显示X轴和Y轴标签和值以及图表标题

发布于 2025-02-11 01:33:09 字数 624 浏览 1 评论 0 原文

我是python的新手,只是遵循教程,但输出与预期 matplotlib 并未在图表上显示任何内容。

这是这里的代码

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
packets = ['1.', '2', '3', '4', '5']
testTime = [2.3,1.7,3.5,2.9,1.2]
plt.bar(packets,testTime)
plt.ylabel('Responsi time (Seconds.milliseconds)')
plt.xlabel('Packets')
plt.title("Response Time")
plt.show()

是输出屏幕截图

”在此处输入图像描述

I am new to python just following a tutorial but the output is not same as expected matplotlib is not showing any thing on chart except the bars.

Here is the code

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
packets = ['1.', '2', '3', '4', '5']
testTime = [2.3,1.7,3.5,2.9,1.2]
plt.bar(packets,testTime)
plt.ylabel('Responsi time (Seconds.milliseconds)')
plt.xlabel('Packets')
plt.title("Response Time")
plt.show()

Here is the output screenshot

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独难免 2025-02-18 01:33:09

通过此图。ADD_AXES([0,0,1,1])轴将覆盖整个图,将其删除或添加分数(小于1),您会没事的:

import matplotlib.pyplot as plt

fig = plt.figure()
# ax = fig.add_axes([0,0,1,1])
packets = ['1.', '2', '3', '4', '5']
testTime = [2.3,1.7,3.5,2.9,1.2]
plt.bar(packets,testTime)
plt.ylabel('Responsi time (Seconds.milliseconds)')
plt.xlabel('Packets')
plt.title="Response Time"
plt.show()

输出:

“

by this fig.add_axes([0,0,1,1]) the axes will cover the whole plot, remove it or add a fraction (less than 1) , and you will be fine :

import matplotlib.pyplot as plt

fig = plt.figure()
# ax = fig.add_axes([0,0,1,1])
packets = ['1.', '2', '3', '4', '5']
testTime = [2.3,1.7,3.5,2.9,1.2]
plt.bar(packets,testTime)
plt.ylabel('Responsi time (Seconds.milliseconds)')
plt.xlabel('Packets')
plt.title="Response Time"
plt.show()

output:

1

清君侧 2025-02-18 01:33:09

除了答案, @eshirvana

如果您不知道要用于 AX .add_axes([[0,0,1,1]),但是,您确实需要Axes ax (例如子图),您可以执行以下操作:

ax = ax =图。ADD_SUBPLOT(111)。这将创建一个1x1的网格,并将子图放在位置1(对将值传递给 add_subplot 的更详细说明意味着可以找到在这里)。

add_subplot()的文档可以找到。以及对

In addition to the answer by @eshirvana:

If you don't know what fractions to use for ax = fig.add_axes([0,0,1,1]), however, you do need the axes ax (e.g. for subplots), you can do the following:

ax = fig.add_subplot(111). This creates a grid of 1x1 and places the subplot at position 1 (a more detailed explanation of what the value passed to add_subplot means can be found here).

The documentation of add_subplot() can be found here. And an explanation for the

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文