How to generate Line Chart from list data based on Python
This article mainly shows you "how to generate a line chart based on Python list data", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to generate a line chart based on Python list data" this article bar.
code
The following is a sample code.
#!/ user/bin/env python# coding= utf-8 ""@project : csdn@author : swordsman Aliang_ALiang@file : draw_pic.py@ide : PyCharm@time : 2022-03-23 09:38:28"""import pandas as pdfrom matplotlib import pyplot as plt _dates = ['2022-03-22 16:45:08', '2022-03-22 16:46:08', '2022-03-22 16:47:08', '2022-03-22 16:48:08', '2022-03-22 16:49:08', '2022-03-22 16:50:08', '2022-03-22 16:51:08', '2022-03-22 16:52:08', '2022-03-22 16:53:08', '2022-03-22 16:54:08']_data1 = [1, 2, 4, 6, 3, 2, 5, 7, 8, 0]_data2 = [0, 9, 8, 2, 1, 0, 6, 5, 2, 1] di = pd.DatetimeIndex(_dates, dtype='datetime64[ns]', freq=None) pd.DataFrame({'data1': _data1}, index=di).plot.line() #Graph abscissa defaults to data index.# plt.savefig(r'data/p1.png', dpi=200)plt.show() #Display currently compiling image pd.DataFrame({'data1': _data1, 'data2': _data2}, index=di).plot.line() #Graph abscissa defaults to data index.# plt.savefig(r'data/p2.png', dpi=200)plt.show() #Show the image code description currently being compiled
1. Time list of x axis: _dates, two sets of list data are prepared, which need to correspond to the number of date lists.
2. Two pictures were made. The second picture was mainly two lines generated on one picture.
verify the effect
The above is "How to generate a line chart from list data based on Python". Thank you for reading this article! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!