Matplotlib how to start ticks, leaving space from the beginning of the axis

I need to display non-numeric data by dates in a simple line graph. I am using matplotlib.

Here is a sample code.

import matplotlib.pyplot as plt xticks=['Jan','Feb','Mar','April','May'] x=[1,2,3,4,5] yticks = ['Windy', 'Sunny', 'Rainy', 'Cloudy', 'Snowy'] y=[2,1,3,5,4] plt.plot(x,y,'bo') #.2,.1,.7,.8 plt.subplots_adjust(left =0.2) plt.xticks(x,xticks) plt.yticks(y,yticks) plt.show() 

Graph generated from code

I want the label labels to leave some space from the origin. So they do not look very crowded. Should I use Fixedlocator for this? I would also like the chart to be a line showing markers for each point, for example, in this example. How can I achieve this?

+4
source share
1 answer
  • You can β€œraise” the chart by setting the lower one using ax.set_ylim .
  • Marker points can be added to the chart using the marker = 'o' parameter in the plt.plot call:

 import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(1, 1, 1) xticks=['Jan','Feb','Mar','April','May'] x=[1,2,3,4,5] yticks = ['Windy', 'Sunny', 'Rainy', 'Cloudy', 'Snowy'] y=[2,1,3,5,4] plt.plot(x,y,'b-', marker = 'o') #.2,.1,.7,.8 plt.subplots_adjust(left =0.2) plt.xticks(x,xticks) plt.yticks(y,yticks) ax.set_ylim(0.5,max(y)) plt.show() 

enter image description here

+6
source

Source: https://habr.com/ru/post/1391754/


All Articles