0

Can you explain this piece of code. I was trying to plot a graph with months on the X axis, I came across this piece of code and I am not able to understand the expression given for start and end parameter for the linespace()

plt.xticks( np.linespace(15, 15 + 30*11 , num = 12), (r'Jan', r'Feb', r'Mar', r'Apr', r'May', r'Jun', r'Jul', r'Aug', r'Sep', r'Oct', r'Nov', r'Dec') )

My exact question is : 1) Why 'r' is used before every month names ? 2) start parameter in linespace() is 15. Does it mean that the first tick should start from the 15th location?

  • 3
    Do you mean [`np.linspace`](https://numpy.org/devdocs/reference/generated/numpy.linspace.html)? this creates an array with `num` elements spanning the range `[15, 15+30*11]` (inclusive) – Michael Delgado Jun 02 '20 at 05:50
  • 2
    Does this answer your question? [What exactly do "u" and "r" string flags do, and what are raw string literals?](https://stackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-and-what-are-raw-string-literals) – Michael Delgado Jun 02 '20 at 05:53
  • 1
    Can you clarify - are you asking about the `r'` string prefix or the `np.linspace` function? They're not related in the code above. If you're asking two questions, please separate them into two questions (or just check out the post above about raw string literals). – Michael Delgado Jun 02 '20 at 05:54
  • 1
    The `linspace` docs should be clear; plus you can easily experiment with it. – hpaulj Jun 02 '20 at 06:24
  • @MichaelDelgado I have edited the question clearly . – Krishna Girish Jun 03 '20 at 05:28
  • 1
    @KrishnaGirish this question was voted by the community to be closed because asking about the purpose of `r'` string prefixes has already been answered in the linked question. In your case, they're unnecssary because there are no special characters - they do nothing. for linspace - yes. the first element is at 15. It's against stack overflow policy to ask two questions in one. See [how to ask](https://stackoverflow.com/help/how-to-ask) for best practices. Cheers! – Michael Delgado Jun 03 '20 at 05:36
  • @ok i got it. Cheers!. – Krishna Girish Jun 03 '20 at 05:44

0 Answers0