Specifying the Graph Start Point in matplotlib

Asked 2 years ago, Updated 2 years ago, 67 views

I have a question about matplotlib.
I'd like to graph two different lengths of data list1, list2.

list1=[1,2,3,4,5]
list2 = [6,7,8]

If there is,

plt.figure()
plt.plot(list1)
plt.plot(list2)
plt.show()

I think the graph of list2 will be output in left column when I put it in this way, but this time I want list2 to be output in the middle (x=2). I wondered if I could range each data, but I didn't know how to do it.
I'd appreciate it if you could let me know if anyone knows how to display the graph halfway. Thank you.

python matplotlib

2022-09-30 21:29

1 Answers

plt.plot can plot data in (x,y) format in the format plt.plot(xdata,ydata).

plt.plot (range(0,5), list1)
plt.plot(range(2,5), list2)

None is treated as missing.

list1=[1,2,3,4,5]
list2 = [None, None, 6, 7, 8]

plt.plot(list1)
plt.plot(list2)


2022-09-30 21:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.