- Главная
- Информатика
- Computational Programming. Part 5
Содержание
- 3. >>> nyc_temp = [53.9, 56.3, 56.4, 53.4, 54.5, 55.8, 56.8, 55.0, 55.3, 54.0, 56.7, 56.4, 57.3]
- 5. Comparing the Monthly Temperature Trends of New York City While still looking at New York City,
- 6. The first list corresponds to the year 2000, and the next two lists correspond to the
- 8. Now we have three plots all on one graph. Python automatically chooses a different color for
- 9. We have a problem, however, because we don’t have any clue as to which color corresponds
- 10. Then, import the legend() function from the pylab module and call it as follows: >>> from
- 11. We call the legend() function with a list of the labels we want to use to
- 13. Customizing Graphs We already learned about one way to customize a graph—by adding a legend. Now,
- 15. Customizing the Axes So far, we’ve allowed the numbers on both axes to be automatically determined
- 16. Now, import the axis() function and call it: >>> from pylab import axis >>> axis() (0.0,
- 17. The function returned a tuple with four numbers corresponding to the range for the x-axis (0.0,
- 19. Saving the Plots If you need to save your graphs, you can do so using the
- 21. Скачать презентацию
>>> nyc_temp = [53.9, 56.3, 56.4, 53.4, 54.5, 55.8, 56.8, 55.0,
>>> nyc_temp = [53.9, 56.3, 56.4, 53.4, 54.5, 55.8, 56.8, 55.0,
We use the range() function we learned about in Chapter 1 to specify
the years 2000 to 2012. Now you’ll see the years displayed on the x-axis
(see Figure 2-7).
Comparing the Monthly Temperature Trends of New York City
While still looking
Comparing the Monthly Temperature Trends of New York City While still looking
>>> nyc_temp_2000 = [31.3, 37.3, 47.2, 51.0, 63.5, 71.3, 72.3, 72.7, 66.0, 57.0, 45.3, 31.1]
>>> nyc_temp_2006 = [40.9, 35.7, 43.1, 55.7, 63.1, 71.0, 77.9, 75.8, 66.6, 56.2, 51.9, 43.6]
>>> nyc_temp_2012 = [37.3, 40.9, 50.9, 54.8, 65.1, 71.0, 78.8, 76.7, 68.8, 58.0, 43.9, 41.5]
The first list corresponds to the year 2000, and the next
The first list corresponds to the year 2000, and the next
>>> months = range(1, 13)
>>> plot(months, nyc_temp_2000, months, nyc_temp_2006, months, nyc_temp_2012)
[
Now we have three plots all on one graph. Python automatically
Now we have three plots all on one graph. Python automatically
>>> plot(months, nyc_temp_2000)
[
We have a problem, however, because we don’t have any clue
We have a problem, however, because we don’t have any clue
>>> plot(months, nyc_temp_2000, months, nyc_temp_2006, months, nyc_temp_2012)
[
Then, import the legend() function from the pylab module and call
Then, import the legend() function from the pylab module and call
>>> from pylab import legend >>> legend([2000, 2006, 2012])
We call the legend() function with a list of the labels
We call the legend() function with a list of the labels
Customizing Graphs
We already learned about one way to customize a graph—by
Customizing Graphs We already learned about one way to customize a graph—by
>>> from pylab import plot, show, title, xlabel, ylabel, legend
>>> plot(months, nyc_temp_2000, months, nyc_temp_2006, months, nyc_temp_2012)
[
Customizing the Axes
So far, we’ve allowed the numbers on both axes
Customizing the Axes So far, we’ve allowed the numbers on both axes
>>> nyc_temp = [53.9, 56.3, 56.4, 53.4, 54.5, 55.8, 56.8, 55.0, 55.3, 54.0, 56.7, 56.4, 57.3]
>>> plot(nyc_temp, marker='o')
[
Now, import the axis() function and call it:
>>> from pylab
Now, import the axis() function and call it:
>>> from pylab
The function returned a tuple with four numbers corresponding to the
range
The function returned a tuple with four numbers corresponding to the range
>>> axis(ymin=0)
(0.0, 12.0, 0, 57.5)
Saving the Plots
If you need to save your graphs, you can
Saving the Plots If you need to save your graphs, you can
>>> from pylab import plot, savefig >>> x = [1, 2, 3] >>> y = [2, 4, 6] >>> plot(x, y) >>> savefig('mygraph.png')