In: Computer Science
For python:
How do I make an y vs x graph where x is from 1 to 20 and y is x times 7
EXPLANATION:
Python provides a tremendous featured library to plotting graph using matplotlib library .Graph is good way to show the data visually (picture type) its the easy way to understand the data stored. We can also customize the graph plotting as our convinence.
In the given problem we need to make an y vs x graph where x is from 1 to 20 and y is x times 7 ,that means each value in the y is 7 times higher than the corresponding x value.
IN Y vs X graph the Y-axis is plotted horizontal direction and the X-axis plotted in vertical diretion
CODE:
OUTPUT:
In the given graph below the scale is :
On x-axis 1unit = 2.5 units
on Y-axis 1 unit = 20 units
RAW_CODE:
#Graph plotting y vs x graph
#y vs x graph means y values are plotted in horizontal direction
and x values are plotted in vertical direction
#inporting numpy library
import numpy as np
#importing pyplot as plt from matplotlib library
import matplotlib.pyplot as plt
#x-axis has values from 1 to 20
x_axis=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
#y-axis has y is x times 7
#that means each value in the y is 7 times to the corresponding
value in x
#storing y values
y=np.array(x_axis)
y_axis=y*7
#plotting y vs x graph with some customizations linke marking the
each co-ordinate with some marker along with color
plt.plot(y_axis, x_axis, color='black', linewidth = 2,
marker='o', markerfacecolor='blue', markersize=7)
#title of the graph
plt.title("Y vs X graph")
#labelling y axis as x axis
plt.ylabel('x axis')
#labelling x axis as y axis
plt.xlabel('y axis')
#showing the plotted graph
plt.show()
**********For any queries comment me in the comment box***********