importio,reimportmatplotlib.pyplotaspltimportpyperclipplt.rcParams['font.family']='sans-serif'plt.rcParams['font.sans-serif']=['Arial']plt.rcParams['pdf.fonttype']=42plt.rcParams['svg.fonttype']='none'plt.rcParams['font.size']=6plt.rcParams['axes.titlesize']=7plt.rcParams['figure.titlesize']=7defcopy_and_show_fig(fig,dpi=450):"""Copies SVG to clipboard and displays figure """buf=io.StringIO()fig.patch.set_visible(False)# remove the global background patchforaxinfig.axes:ax.patch.set_visible(False)# remove each Axes background patchfig.savefig(buf,format='svg',transparent=True,bbox_inches='tight',pad_inches=0)svg_data=buf.getvalue()# patch width/height from pt to pxm=re.search(r'viewBox="\s*([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)"',svg_data)w_pt,h_pt=float(m.group(3)),float(m.group(4))w_px=int(round(w_pt*dpi/72))h_px=int(round(h_pt*dpi/72))svg_data=re.sub(r'(<svg[^>]*?)width="[^"]+"',rf'\1width="{w_px}px"',svg_data,count=1)svg_data=re.sub(r'(<svg[^>]*?)height="[^"]+"',rf'\1height="{h_px}px"',svg_data,count=1)pyperclip.copy(svg_data)fig.set_dpi(200)fig.patch.set_visible(True)fig,ax=plt.subplots(figsize=(3.5,2.33))# Corresponds to 183 mm width# This is a simple exampley=range(1,10)x=range(len(y))ax.bar(x,y)ax.set_title('A simple bar plot')ax.set_xlabel('Item ID')ax.set_ylabel('Number of items')ax.spines['right'].set_visible(False)ax.spines['top'].set_visible(False)# Draw your figure and copy SVG to clipboardcopy_and_show_fig(fig)