Understanding matplotlib xticks syntax

前端 未结 2 1545
[愿得一人]
[愿得一人] 2021-02-05 11:01

I am reading a book and I came across this code:

import matplotlib.pyplot as plt
plt.scatter(x,y)
plt.title(\"Web traffic over the last month\")
plt.xlabel(\"Tim         


        
2条回答
  •  面向向阳花
    2021-02-05 12:00

    In order to understand range, open python and write in sequence the following commands:

     range(7) 
     range(4,8) 
     range(3,11,2)
    

    For the list comprehensions within the plt.xticks, they are basically a compact way of writing loops. They are very common, useful and neat. In order to understand them:

     [w*2 for w in range(10)] 
     [w*2 for w in range(10) if w < 4] 
    

    Finally, for the command plt.xticks itself you can check http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xticks for a very brief explanation with simple examples.

提交回复
热议问题