Ale*_*lex 3 python geometry matplotlib legend
我为莫尔圆中的有效应力构建了一个非常简化的代码。这是我的代码:
\n\nfrom mpl_toolkits.mplot3d import * # f\xc3\xbcr Druckplots ben\xc3\xb6tigt\nfrom matplotlib import cm\nfrom math import * # f\xc3\xbcr pi und exp ben\xc3\xb6tigt\nfrom scipy.special import * # f\xc3\xbcr expn ben\xc3\xb6tigt\nimport matplotlib.pyplot as plt # f\xc3\xbcr Plotting in 2D/3D ben\xc3\xb6tigt\nimport numpy as np # f\xc3\xbcr f\xc3\xbcr Arrays ben\xc3\xb6tigt\nimport matplotlib.lines as mlines\nimport os\nclear = lambda: os.system(\'cls\')\nclear()\n#==============================================================================\n# Mohr Cirlce\n#==============================================================================\n\n#depth = 3000.0 # Reservoirtiefe\n#density = 2700.0 # Dichte des \xc3\xbcberlagernden Gesteins\n#G = 12700.0 # shear modulus [MPa]\n#E = 26000.0 # Young\xc2\xb4s modulus in [MPa]\n#sv = 9.81*density*depth/1e6 # vertical stress\n#sh = 0.5*sv # minimum horizontal stress\ncf1 = 4.0 # Cohesion C Fault1 [MPa] \nmuef1 = 0.5 # coefficient of friction [MPa]\n#f1dip = 45 # Einfallen der St\xc3\xb6rung\np0 = 15.0 # initial pore pressure [MPa]\n\n# Mohr failure criterion ##\nsigman = np.zeros((80))\ntauf1 = np.zeros((80))\nfor i in range(0,80):\n sigman[i] = i\n tauf1[i] = muef1*sigman[i]+cf1 # Bruchgerade\n\n## Stresses ##\nsH = 60.0\nsh = 30.0 \nsmean = float((sH+sh)/2) # Kreismittelpunkt\nshear = float((sH-sh)/2) # Kreisradius\n\n## Effective Stresses ##\nsHeff = sH-p0 # effektive Vertikalspannung\nsheff = sh-p0 # effektive Horizontalspannung\nsmeaneff = float((sHeff+sheff)/2) # Kreismittelpunkt\nsheareff = float((sHeff-sheff)/2) # Kreisradius\n\n## Plotting ## \nfig=plt.figure()\nax=fig.add_subplot(1,1,1)\nplt.plot(sigman, tauf1, "b", linewidth=1, linestyle="-", label="Bruchgerade")\nax.axis(\'scaled\')\nmohr=plt.Circle((smean,0), radius=shear, color=\'g\', fill=False, label = "Mohr")\nmohreff=plt.Circle((smeaneff,0), radius=sheareff, color=\'r\', fill=False)\nplt.title("Mohrkreise bei ...")\nax.set_xlabel(\'$\\sigma$ [MPa]\', fontsize=12)\nax.set_ylabel(\'$\\tau$ [MPa]\', fontsize=12)\nplt.xticks(np.arange(0, 90, 10))\nplt.yticks(np.arange(0, 45, 5))\nplt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., numpoints = 1)\nax.add_patch(mohr)\nax.add_patch(mohreff)\nplt.show()\nRun Code Online (Sandbox Code Playgroud)\n\n我的绿色圆圈代表初始应力,红色圆圈代表有效应力。我想在我的图例中为这两个圆圈添加标签,这可能吗?到目前为止我还没有找到任何解决方案。
\n\n干杯,\nA.
\n哦!莫尔圆!
对于较低级别的界面,它不会自动处理(即手动创建艺术家并添加它)。因此,您需要将艺术家和唱片公司传递到legend.
举个简单的例子:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
circ = plt.Circle((0.5, 0), 0.3, facecolor='none', edgecolor='red')
ax.add_patch(circ)
ax.legend([circ], ['Stress State'])
# The rest is purely optional and just for appearance.
ax.axhline(0, color='black')
ax.axvline(0, color='black')
ax.margins(0.05)
ax.axis('scaled')
ax.set(xlabel=r'Normal Stress', ylabel=r'Shear Stress')
plt.show()
Run Code Online (Sandbox Code Playgroud)
