I have been trying to make a python program that will get the values : m, x, c. And plot a graph using the equation y = mx+c.
Im also adding a gui to this.
I'm using matplotlib, tkinter and numpy to achieve this.
Code snippet:
Is this a defect in matplotlib or am I using it wrong.
Thanks for spending your time to help!
~Oshadha
Im also adding a gui to this.
I'm using matplotlib, tkinter and numpy to achieve this.
Code snippet:
from matplotlib import pyplot as plt
import numpy as np
from tkinter import *
def plot():
try:
m_val = int(Em.get()) #Em stands for entry m. Tkinter stuff
x_val = int(Ex.get()) #x_val stands for x value & is used in calculations
c_val = int(Ec.get())
except TypeError as err:
#error(err)
pass
_x = np.linspace(-5,5,100)
_y = m_val*x_val+c_val
plt.plot(_x, _y, '-r', label=f'y={m_val}*{x_val}+{c_val}')
plt.title('Graph of y=2x+1')
plt.xlabel('x', color='#1C2833')
plt.ylabel('y', color='#1C2833')
plt.legend(loc='upper left')
plt.grid()
plt.show()I get this:Error: raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (100,) and (1,)Traceback:Error: line 39, in plot plt.plot(_x, _y, '-r', label=f'y={m_val}*{x_val}+{c_val}')I have used matplotlib before, and when x & y values are not equal, I seem to get the same error.Is this a defect in matplotlib or am I using it wrong.
Thanks for spending your time to help!
~Oshadha
