2

I am giving an example of what I am trying to plot.

big_list = [[12,13,-12],[1,5,9,10,12],[-1,-2]]
plt.plot(big_list.index,big_list)
plt.show()

Output:

ValueError: x and y must have same first dimension, but have shapes (1,) and (31906,)

2 Answers 2

1

IIUC you want to plot all sub-lists on the same figure:

for list in big_list:
    plt.plot(list)

If not please comment. It's not clear to me what you want you your x axis.

Update based on comment:

In this case you can do:

from matplotlib.ticker import MaxNLocator
for i,list in enumerate(big_list):
    plt.scatter([i]*len(list), list)
plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))

enter image description here

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

3 Comments

This looks good. The problem with it is, all elements of a sub-list are not drawn on a same index. Instead, a range of index equal to the number of elements is considered. This is not what I wanted. I want all the elements of a sub-list on same index.
Please see my update for this case (or use boxplots as in your answer).
This looks good than box plots I thought. I shall take it. Thanks
0

After trial and error, I found the box plots is what I wanted. I have three sub-lists and box plot produces three indexes on x-axis and produces a box on y-axis in proportionate to the values in the sub-list.

My code:

plt.boxplot(big_list)
plt.show() 

Output:

enter image description here

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.