gpt4 book ai didi

python - matplotlib 中圆圈的标签

转载 作者:太空宇宙 更新时间:2023-11-04 01:11:04 27 4
gpt4 key购买 nike

我已经为莫尔圆中的有效应力构建了一个非常简化的代码。这是我的代码:

from mpl_toolkits.mplot3d import *     # für Druckplots benötigt
from matplotlib import cm
from math import * # für pi und exp benötigt
from scipy.special import * # für expn benötigt
import matplotlib.pyplot as plt # für Plotting in 2D/3D benötigt
import numpy as np # für für Arrays benötigt
import matplotlib.lines as mlines
import os
clear = lambda: os.system('cls')
clear()
#==============================================================================
# Mohr Cirlce
#==============================================================================

#depth = 3000.0 # Reservoirtiefe
#density = 2700.0 # Dichte des überlagernden Gesteins
#G = 12700.0 # shear modulus [MPa]
#E = 26000.0 # Young´s modulus in [MPa]
#sv = 9.81*density*depth/1e6 # vertical stress
#sh = 0.5*sv # minimum horizontal stress
cf1 = 4.0 # Cohesion C Fault1 [MPa]
muef1 = 0.5 # coefficient of friction [MPa]
#f1dip = 45 # Einfallen der Störung
p0 = 15.0 # initial pore pressure [MPa]

# Mohr failure criterion ##
sigman = np.zeros((80))
tauf1 = np.zeros((80))
for i in range(0,80):
sigman[i] = i
tauf1[i] = muef1*sigman[i]+cf1 # Bruchgerade

## Stresses ##
sH = 60.0
sh = 30.0
smean = float((sH+sh)/2) # Kreismittelpunkt
shear = float((sH-sh)/2) # Kreisradius

## Effective Stresses ##
sHeff = sH-p0 # effektive Vertikalspannung
sheff = sh-p0 # effektive Horizontalspannung
smeaneff = float((sHeff+sheff)/2) # Kreismittelpunkt
sheareff = float((sHeff-sheff)/2) # Kreisradius

## Plotting ##
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
plt.plot(sigman, tauf1, "b", linewidth=1, linestyle="-", label="Bruchgerade")
ax.axis('scaled')
mohr=plt.Circle((smean,0), radius=shear, color='g', fill=False, label = "Mohr")
mohreff=plt.Circle((smeaneff,0), radius=sheareff, color='r', fill=False)
plt.title("Mohrkreise bei ...")
ax.set_xlabel('$\sigma$ [MPa]', fontsize=12)
ax.set_ylabel('$\tau$ [MPa]', fontsize=12)
plt.xticks(np.arange(0, 90, 10))
plt.yticks(np.arange(0, 45, 5))
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., numpoints = 1)
ax.add_patch(mohr)
ax.add_patch(mohreff)
plt.show()

我的绿色圆圈代表初始应力,我的红色圆圈代表有效应力。我想在我的图例中为这两个圆圈添加标签,这可能吗?到目前为止我没有找到任何解决方案。

干杯,A.

最佳答案

哦!莫尔圆!

它不会为较低级别的界面自动处理(即手动创建艺术家并添加它)。因此,您需要将艺术家和标签传递给 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()

enter image description here

关于python - matplotlib 中圆圈的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27629656/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com