In thisPython tutorial, we will discussPut legend outside plot matplotlibin python. Here we will cover different examples related to legend outside plot usingmatplotlib. And we will also cover the following topics: Put legend outside plot matplotlib Matplotlib set legend outside plot Matplotlib set...
import matplotlib.pyplot as plt line1, = plt.plot([1,2,3], label="Line 1", linestyle='--') line2, = plt.plot([3,2,1], label="Line 2", linewidth=4) # 为第一个线条创建图例 first_legend = plt.legend(handles=[line1], loc=1) # 手动将图例添加到当前轴域 ax = plt.gca()....
plt.legend(loc='best',frameon=False)#去掉图例边框plt.legend(loc='best',edgecolor='blue')#设置图例边框颜色plt.legend(loc='best',facecolor='blue')#设置图例背景颜色,若无边框,参数无效 对于边框还可以采用面向对象方式: legend = plt.legend(["First","Second"]) frame=legend.get_frame() frame.set...
plt.plot(x, np.sin(x),'-g', label='sin(x)') plt.plot(x, np.cos(x),':b', label='cos(x)') plt.axis('equal') plt.legend(); 上图可见,plt.legend()函数绘制的图例线条与图中的折线无论风格和颜色都保持一致。查阅plt.legend文档字...
plt.legend(loc='best',facecolor='blue') #设置图例背景颜色,若无边框,参数无效 1. 2. 3. 对于边框还可以采用面向对象方式: legend = plt.legend(["First", "Second"]) frame = legend.get_frame() frame.set_facecolor('blue') 1. 2.
["axes.unicode_minus"] = False import matplotlib.pyplot as plt import numpy as np x = np.linspace(-2*np.pi,2*np.pi,200) y = np.sin(x) y1 = np.cos(x) plt.plot(x,y,label = r"$\sin(x)$") plt.plot(x,y1,label = r"$\cos(x)$") plt.legend() plt.title("正弦函数和...
avail.legend(['ON', 'PLANNED', 'STOP']) #criando figura para plotar dentro do TKinter canvas_avail = FigureCanvasTkAgg(fig2, master=root) canvas_avail.get_tk_widget().place(x=10, y=0) root.mainloop() Proof: (查看英文版本获取更加准确信息)...
This process creates a figure with two scatter plots and a legend placed at thecenter leftof the axes’ border-box. Add a Legend to the 3D Scatter Plot in Matplotlib importmatplotlib.pyplotasplt x=[1,2,3,4,5]y=[2,1,4,5,6]z1=[i+jfor(i,j)inzip(x,y)]z2=[3*i-jfor(i,j...
l1 = ax.plot(x1,y,'ys-') l2 = ax.plot(x2,y,'go--') ax.legend(labels = ('tv', 'Smartphone'), loc = 'lower right') # legend placed at lower right ax.set_title("Advertisement effect on sales") ax.set_xlabel('medium') ...
How to add the default matplotlib legend Legend location, learn how to add it anywhere including outside the plot area Customize the legend label appearance Add and customize the title of the legend Customize the marker of each element item ...