How to generate a graph with distinct X and Y with the matplotlib module in Python?

Asked

Viewed 174 times

-1

The objective would be to generate a bar graph where the Y axis goes from 0 to 10 (fixed mode), and the user would inform the maximum value of X (the X axis being constituted of 1 until the informed value).

1 answer

0

I don’t know if I understood your doubt correctly, but take a look at this solution that I created the value of Y is fixed from 0 to 10 and X is variable according to what the user type.

Note: X values are stored in a list for easy reading.

import matplotlib.pyplot as plt

lista = []

for i in range(11):
    num = float(input('Digite a posição {}: '.format(i)))
    lista.append(num)

y = range(0,11)
x = lista
plt.ylabel(u'Eixo Y')
plt.xlabel(u'Eixo X')
plt.grid(True)
plt.bar(x, y)

plt.show()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.