问题描述
我尝试使用 matplotlib 库绘制梁的应力.
I try to plot stress of beam by using matplotlib library.
我已经使用公式计算并绘制了示例:
I have calculated by using formulas and plot it for an example:
如图1所示,您将看到绿色光束在元素3和元素8处的应力更大.因此,如果我通过彩虹渐变填充颜色,则整个蓝色光束将具有相同的颜色,但是绿色光束将具有元素3和8的不同颜色将比其他颜色更红.
As Figure 1, you will see that the green beam has more stress at element 3 and also element 8 Thus if i fill the color by rainbow gradient,The over all of blue beam will be same color but The green beam will have different color by the element 3 and 8 will be going to red side more than others.
这是我的一些代码和结果.
Here is some of my code and result.
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np
node_coordinate = {1: [0.0, 1.0], 2: [0.0, 0.0], 3: [4.018905, 0.87781],
4: [3.978008, -0.1229], 5: [1.983549, -0.038322],
6: [2.013683, 0.958586], 7: [3.018193, 0.922264],
8: [2.979695, -0.079299], 9: [1.0070439, 0.989987],
10: [0.9909098, -0.014787999999999999]}
element_stress = {1: 0.2572e+01, 2: 0.8214e+00, 3: 0.5689e+01,
4: -0.8214e+00, 5: -0.2572e+01, 6: -0.4292e+01,
7: 0.4292e+01, 8: -0.5689e+01}
n = len(element_stress.keys())
x = np.empty(n)
y = np.empty(n)
d = np.empty(n)
for i in element_stress.keys():
x[i-1] = node_coordinate[i][0]
y[i-1] = node_coordinate[i][1]
d[i-1] = element_stress[i]
mask = np.logical_or(x < 1.e20, y < 1.e20)
x = np.compress(mask, x)
y = np.compress(mask, y)
triang = tri.Triangulation(x, y)
cmap = mpl.cm.jet
fig = plt.figure(figsize=(80, 40))
ax1 = fig.add_axes([0.05, 0.80, 0.9, 0.15])
cax = ax1.tricontourf(triang, d, cmap=cmap)
fig.colorbar(cax)
plt.show()
您将看到我知道所有节点坐标以及元素的应力值.
You will see that i know all of node co-ordinate and also element's stress value.
但是我的图的颜色不平滑,没有像上面的示例图那样横向排列.
But the color of my figure is not smooth and not arrange in horizontal as the example figure above.
怎么做呢?
p.s.对不起,我的语法不是我的母语.
p.s. Sorry for my grammar, I'm not native.
谢谢.求建议.
推荐答案
增加等高线级别的数量会使绘图看起来更平滑.例如.101 级,
Increasing the number of contour levels would make the plot appear more smooth.E.g. for 101 levels,
levels=np.linspace(d.min(), d.max(), num=101)
tri = ax1.tricontourf(triang, d, cmap=cmap, levels=levels)
fig.colorbar(tri)
这篇关于如何通过matplotlib在矩形条上绘制温度(应力)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!