龙空技术网

Matplotlib--在图像中使用LaTex公式及标注箭头的使用

欢乐大杂烩 388

前言:

当前同学们对“python画箭头”可能比较关心,咱们都想要分析一些“python画箭头”的相关资讯。那么小编也在网上搜集了一些有关“python画箭头””的相关知识,希望看官们能喜欢,朋友们一起来了解一下吧!

u=[0,0,0,1,-1]c=[0.5,0.7,1,1,1]import numpy as npimport matplotlib.pyplot as pltplt.rcParams['font.sans-serif']=['Times new Roman']plt.rcParams['axes.unicode_minus'] = Falsex=np.linspace(-5,5,100)fig=plt.figure(figsize=(6,4))ax1=plt.subplot(1,1,1)ax1legend=[]for i in range(len(u)):    y1=(1/(c[i]*np.sqrt(2*np.pi)))*np.exp(-(x-u[i])**2/(2*(c[i]**2)))    ax1.plot(x,y1,label='μ='+str(u[i])+',  '+'σ='+str(c[i]))ax1.set_xlabel('x',fontsize=17,fontname='Times new Roman',fontstyle='italic')ax1.set_ylabel('f (x)',fontsize=17,fontname='Times new Roman',fontstyle='italic')labels = ax1.get_xticklabels() + ax1.get_yticklabels()[label.set_fontname('Times New Roman') for label in labels][label.set_fontsize(15) for label in labels]plt.legend(fontsize=13)from matplotlib.pyplot import MultipleLocator#从pyplot导入MultipleLocator类,这个类用于设置刻度间隔y_major_locator=MultipleLocator(0.2)#把y轴的刻度间隔设置为10,并存在变量里ax1.yaxis.set_major_locator(y_major_locator)#把y轴的主刻度设置为10的倍数plt.rcParams['mathtext.fontset'] = 'stix'ax1.annotate('标准正态分布',xy=(0,0.4), xytext=(-4.5, 0.6),xycoords='data',arrowprops=dict(arrowstyle='->'),fontname='STZhongsong',fontsize=14)ax1.text(-5,0.4,r'$f(x)=\frac{1}{\sqrt{2\pi}}e^{\frac{-x^2}{2}}$',fontsize=20)plt.show()# fig.savefig(r'C:\Users\mxs\Desktop\guass_distribution',dpi=300,bbox_inches = 'tight')
#!/usr/bin/env python#coding:utf-8"""  Author:  Chaos --<Chaosimpler@gmail.com>  Purpose: 在Matplotlib绘图过程中使用Latex风格的公式  Created: 2014年10月17日"""import matplotlib.pyplot as pltimport numpy as npif __name__ == '__main__':        x=np.arange(0.01,1,0.01)    y=0.5*np.log((1-x)/x)       plt.grid()        plt.subplots_adjust(top=0.9)    plt.scatter(x,y,label=r'$\alpha =\frac{1}{2}\ln(\frac{1-\varepsilon}{\varepsilon })$')        plt.legend()    plt.xlabel(r'$\varepsilon$',fontsize=20)    plt.ylabel(r'$\alpha$',fontsize=20)    plt.xlim(0,1)        plt.show()
import matplotlib.pyplot as pltax=plt.subplot(111)# ax.text(0.1,0.8,r"$\usepackage{unicode-math}\setmathfont{Cambria Math}\int_a^b f(x)\mathrm{d}x$",fontsize=30)plt.rcParams['mathtext.fontset'] = 'stix'ax.text(0.1,0.3,r"$\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}!$",fontsize=30)plt.show()

标签: #python画箭头