📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 313definition

LINE CHART, PIE CHART AND BAR CHART · Part 2

Chapter 4: 6 · COMPUTER SCIENCE

you to see your graph. You can hover the graph and see the coordinates in the bottom right. Example . .

Figure . 12th Computer Chapter - - You may be wondering why the x-axis ranges from - and the y-axis from - . If you provide a single list or array to the plot () command, matplotlib assumes it is a sequence of y values, and automatically generates the x values for you. Since python ranges start with , the default x vector has the same length as y but starts with .

Hence the x data are [ , , , ]. plot() is a versatile command, and will take an arbitrary number of arguments. For example, to plot x and y, you can issue the command: import matplotlib.pyplot as plt plt.plot([ , , , ], [ , , , ]) plt.show() Program This .plot takes many arguments, but the first two here are 'x' and 'y' coordinates. This means, you have co-ordinates according to these lists: ( , ), ( , ), ( , ) and ( , ).

12th Computer Chapter - - Data Visualization using Pyplot Plotting Two Lines To plot two lines, use the following code: import matplotlib.pyplot as plt x = [ , , ] y = [ , , ] x2 = [ , , ] y2 = [ , , ] plt.plot(x, y, label='Line ') plt.plot(x2, y2, label='Line ') plt.xlabel('X-Axis') plt.ylabel('Y-Axis') plt.title('LINE GRAPH') plt.legend() plt.show() Output With plt.xlabel and plt.ylabel, you can assign labels to those respective axis. Next, you can assign the plot's title with plt.title, and then you can invoke the default legend with plt. legend(). LINE GRAPH Y - Axis X - Axis .

Line1 Line2 Figure . 12th Computer Chapter - - Buttons in the output In the output figure, you can see few buttons at the bottom left corner. Let us see the use of these buttons. Home Button Forward

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →