numpy - Python: plot list of tuples -


i have following data set. use python or gnuplot plot data. tuples of form (x,y). y axis should log axis. i.e. log(y). scatter plot or line plot ideal.

how can done?

 [(0, 6.0705199999997801e-08), (1, 2.1015700100300739e-08),   (2, 7.6280656623374823e-09), (3, 5.7348209304555086e-09),   (4, 3.6812203579604238e-09), (5, 4.1572516753310418e-09)] 

if question correctly, this.

>>> import matplotlib.pyplot plt >>> testlist =[(0, 6.0705199999997801e-08), (1, 2.1015700100300739e-08),   (2, 7.6280656623374823e-09), (3, 5.7348209304555086e-09),   (4, 3.6812203579604238e-09), (5, 4.1572516753310418e-09)] >>> math import log >>> testlist2 = [(elem1, log(elem2)) elem1, elem2 in testlist] >>> testlist2 [(0, -16.617236475334405), (1, -17.67799605473062), (2, -18.691431541177973), (3, -18.9767093108359), (4, -19.420021520728017), (5, -19.298411635970396)] >>> zip(*testlist2) [(0, 1, 2, 3, 4, 5), (-16.617236475334405, -17.67799605473062, -18.691431541177973, -18.9767093108359, -19.420021520728017, -19.298411635970396)] >>> plt.scatter(*zip(*testlist2)) >>> plt.show() 

which give like

enter image description here

or line plot,

>>> plt.plot(*zip(*testlist2)) >>> plt.show() 

enter image description here

edit - if want add title , labels axis, like

>>> plt.scatter(*zip(*testlist2)) >>> plt.title('random figure') >>> plt.xlabel('x-axis') >>> plt.ylabel('y-axis') >>> plt.show() 

which give you

enter image description here


Comments

Popular posts from this blog

c++ - Linked List error when inserting for the last time -

java - activate/deactivate sonar maven plugin by profile? -

tsql - Pivot with Temp Table (definition for column must include data type) -- SQL Server 2008 -