1

Ok, the problem is quite simple, I guess. What I'm trying to do is a bar plot where the data is plotted in sequence, ignoring if the current value is smaller than the previous one. For example, the following:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

for index in range(len(x)): 
    plt.bar(x[index], y[index])

returns me this plot:

enter image description here

But if I add a new value to x and y (the new x value being smaller than the previous value), like:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2]
y = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200]

for index in range(len(x)): 
    plt.bar(x[index], y[index])

the plot goes like this:

enter image description here

So, finally, how can I plot this new 2 value after 10 instead of going back right to the value previously plotted?

0

1 Answer 1

3

Plot the against the range value and adjust the ticks label:

plt.bar(range(len(x)), y)
plt.xticks(range(len(x)), x)

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.