gpt4 book ai didi

python - 使用 matplotlib 在 Python 中未显示绘图

转载 作者:太空宇宙 更新时间:2023-11-04 00:54:37 25 4
gpt4 key购买 nike

我在 64 位 Windows 10 桌面上使用 Windows 7。我正在尝试根据给出的代码绘制图表:

import matplotlib.pyplot as plt
from collections import Counter

def make_chart_simple_line_chart(plt):

years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3]

# create a line chart, years on x-axis, gdp on y-axis
plt.plot(years, gdp, color='green', marker='o', linestyle='solid')

# add a title
plt.title("Nominal GDP")

# add a label to the y-axis
plt.ylabel("Billions of $")
plt.show()

我看过其他问题,但似乎找不到答案,除非我看错了地方。我已经检查了后端,它是“Qt4Agg”,我认为它应该是正确的后端,但它仍然没有显示。我没有收到任何错误,只是没有显示情节。我是 Python 的新手,所以这对我有很大帮助。谢谢!

最佳答案

您需要做的就是在现有代码下方调用您的函数:

make_chart_simple_line_chart(plt)

所以总的代码是这样的:

import matplotlib.pyplot as plt
from collections import Counter

def make_chart_simple_line_chart(plt):

years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3]

# create a line chart, years on x-axis, gdp on y-axis
plt.plot(years, gdp, color='green', marker='o', linestyle='solid')

# add a title
plt.title("Nominal GDP")

# add a label to the y-axis
plt.ylabel("Billions of $")
plt.show()

make_chart_simple_line_chart(plt)

关于python - 使用 matplotlib 在 Python 中未显示绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35617715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com