Matplotlib Cheat Sheet (Class 12 IP)
Code Meaning
plt.plot(x,y) Draws a line graph between x and y
plt.title('Name') Adds a title to the graph
plt.xlabel('X-axis') Labels the X-axis
plt.ylabel('Y-axis') Labels the Y-axis
plt.xticks([1,2,3],['A','B','C']) Custom ticks/labels on X-axis
plt.yticks([10,20,30]) Sets Y-axis ticks (scale values)
plt.bar(x,y) Vertical bar chart
plt.barh(x,y) Horizontal bar chart
plt.hist(data,bins=5) Histogram with 5 intervals
plt.pie(sizes,labels=names) Pie chart with labels
plt.grid(True) Shows grid lines
plt.legend() Displays legend (labels of plots)
plt.subplot(r,c,n) Multiple plots (row, col, number)
plt.show() Displays the final graph
Line Styles Meaning
linestyle='-' Solid line (default)
linestyle='--' Dashed line
linestyle=':' Dotted line
linestyle='-.' Dash-dot line
Marker Styles Meaning
marker='o' Circle marker
marker='s' Square marker
marker='^' Triangle marker
marker='*' Star marker
marker='d' Diamond marker
Color Codes Meaning
color='r' Red
color='g' Green
color='b' Blue
color='k' Black
color='y' Yellow