NameError: name 'x' is not defined のエラーが出ました。
# coding: utf-8 from __future__ import absolute_import from __future__ import division from __future__ import print_function import os import numpy as np import numpy.random as random import matplotlib.pyplot as plt plt.plot(x,40/(x+1),label=r'需要$=\frac{40}{x+1}$') plt.plot(x,x**2,label='供給$=x^2$') plt.legend() plt.xlabel('価格') plt.ylabel('人数') plt.xlim((0,6)) plt.ylim((1,1000)) plt.yscale('log') plt.hlines(10,0,6,linestyles='dashed') plt.vlines([3,3.14,3.28],1,1000,linestyles='dotted')
と書いたコードを実行したときに
Traceback (most recent call last):
File "test7.py", line 13, in <module>
plt.plot(x,40/(x+1),label=r'需要$=\frac{40}{x+1}$')
NameError: name 'x' is not defined
とエラーが出ました。
![]
画像のようなグラフを実行したいのですが、
何が足りないのでしょうか?
plt.plot(x,40/(x+1),label=r'需要$=\frac{40}{x+1}$') plt.plot(x,x**2,label='供給$=x^2$')
のplotの第一引数でxを定義していると思うのですが。。。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。