You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ax.set_xlabel(‘angle’)
x= [0,2,4,6]
label= ['zero','two','four','six']
#Method 1:ax.set_xticks(x) #denote the positions on corresponding action where ticks will be displayed.ax.set_xticklabels(label) #labels corresponding to tick marks#Method 2:ax.set(xticks=x, xticklabels=label)
2.3.4. Legend
Label when there are multiple plots on same axes
plt.plot([1, 2, 3], [10, 20, 25], color='black', label='city1')
plt.plot([1, 2, 3], [30, 23, 13], color='orange', label='city2')
plt.scatter([1, 2, 3], [20, 10, 30], color='salmon', label='city3')
plt.legend() #Need to call .legend() to display label#plt.legend(loc='upper left') #To display where to put the label boxplt.show()
3. Common Plots
Scatter
Line
Bar
Histogram
fig, ((ax1, ax2), (ax3, ax4)) =plt.subplots(nrows=2, ncols=2, figsize=(10, 10), sharex='all', sharey='all') #sharex='all', sharey='all' to share same axis x, yax1.set(title='Scatter')
ax2.set(title='Line')
ax3.set(title='Bar')
ax4.set(title='Bar with Artists')
ax1.scatter(x,y, marker="+", color="red")
ax2.plot(x,y,marker='*', linestyle='dashed', color="black")
ax3.bar(x,y, edgecolor='black', color='lightblue')
bars=ax4.bar(x,y, color='lightblue')
forbar, heightinzip(bars, y):
ifheight<0:
bar.set(color='salmon') #To change the color of each bar based on Height valuesplt.show();