【问题标题】:Why wont my graph plot correctly?为什么我的图表不能正确绘制?
【发布时间】:2016-07-12 02:12:34
【问题描述】:

我正在尝试绘制图形 y= 5*x - 300/x,但我的输出只是一条直线,我不明白为什么。任何人都可以帮忙吗?谢谢

xvls= []
Rvls= []

for x in range(-100,100,1):

    if x != 0:
       def R(x):
           f1 = 5*x
           f2 = 300/x
           f3 = f1+f2
           return f3
       error = 10
       while error >= 1e-6:
           error = R(x)-x
           x = x -error
           Rvls.append(R(x))
           xvls.append(x)
    else:
        print 0 

fig = plt.figure(figsize=(10,5))
xvls=np.linspace(-300,300, 25)
Rvls= np.linspace(-300,300, 25)
plt.subplot(1,2, 1)
plt.plot(xvls, Rvls, linestyle='-', marker='o', color='blue')
plt.xlabel('Distance from right hand pin')
plt.ylabel('Reaction force at left hand pin')
plt.title('The relationship between R(x) and x')
plt.rc('font', size=12)
plt.grid()

【问题讨论】:

    标签: python plot graph spyder


    【解决方案1】:

    我认为 linspace 返回给定值之间的线的值。

    【讨论】:

      【解决方案2】:

      线条

      xvls=np.linspace(-300,300, 25)
      Rvls= np.linspace(-300,300, 25)
      

      覆盖您之前所做的所有计算。你可能想把它们排除在外。

      【讨论】:

        【解决方案3】:

        我猜f2 = 300/x 这行可能是罪魁祸首。如果您使用 Python 2.x f2 将计算为整数,因为 300 和 x 都是整数。它不能解释你得到一条直线的事实,但你还没有给出一个完全可编译的代码示例来进行故障排除。您能否提供编译和产生问题所需的最少代码?

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-02-03
          • 2012-06-15
          • 2012-06-24
          • 1970-01-01
          • 1970-01-01
          • 2021-11-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多