我想寻求帮助。请帮助我编写 Python 2.7 中的代码。我想绘制气体释放的浓度。两周前我开始接触 Python,我之前没有看到它,我对 Pascal 有基本的了解,但它是不同的语言。
我不知道为什么不起作用...
这张图片展示了它的外观:flickr.com/photos/95370861@N02/8696658905/in/photostream/lightbox/
我的代码:
from __future__ import division
from matplotlib.patches import Polygon, Rectangle
import math
import numpy as np
import matplotlib.pyplot as plt
def draw(x, y,ax, color, lw=1):
xr, yr = np.copy(x)[::-1], np.copy(y)[::-1]
for i in range(len(y)):
y[i] = -y[i]
verts = zip(x.tolist() + xr.tolist(), y.tolist() + yr.tolist())
poly = Polygon(verts, facecolor=color, edgecolor='k', lw=lw)
ax.add_patch(poly)
def concentration_chart_plume(x,y, ax, ticks, colors, title):
maxX = 0
for tick, color in zip(ticks[::-1], colors):
x, y = calculation(tick)
draw(np.array(x), np.array(y), ax, color)
maxX = max([maxX] + x)
''' plot parameters '''
plt.xlim(0, maxX)
plt.axis('equal')
plt.xlabel('$x[m]$')
plt.ylabel('$y[m]$')
plt.title(title)
sqrs = [Rectangle((0, 0), 1, 1, fc=clr) for clr in colors[::-1]]
desc = ["> %g" % tick for tick in ticks]
plt.legend(sqrs, desc, title="Concentration $kg/m^3$")
plt.grid()
def calculation(tick,m):
cx = FILE_1
sy = FILE_2
x = FILE_3
y = [sy * np.sqrt(2 * np.log(cx / (tick)))] #I do not know, how can be limited to non-zero values
return (x, y)
if __name__ == "__main__":
''' Concentration plot of continuous gas release '''
title = u"conturs"
colors = ["#9EFF00", "#FFF500", "#FF9900", "#FF2E00"]
ticks = [0.1, 1e-2, 1e-3, 1e-4] # value of concentration kg/m3, I want to show up
fig = plt.figure()
ax = fig.gca()
plt.show()
FILE_1 值:
[ 2.21000000e+00 2.19000000e+00 2.16000000e+00 2.12000000e+00
2.08000000e+00 1.90000000e+00 1.71000000e+00 1.18000000e+00
7.93000000e-01 3.55000000e-01 1.93000000e-01 7.02500000e-02
3.70800000e-02 1.37100000e-02 7.42100000e-03 4.77800000e-03
3.39200000e-03 2.56200000e-03 2.02100000e-03 1.64600000e-03
1.37300000e-03 1.16800000e-03 1.00900000e-03 8.82300000e-04
7.80300000e-04 6.96400000e-04 6.26500000e-04 5.67500000e-04
5.17200000e-04 4.73800000e-04 4.36200000e-04 4.03200000e-04
3.74200000e-04 3.48500000e-04 3.25600000e-04 3.05100000e-04
2.86700000e-04 2.70000000e-04 2.54900000e-04 2.28500000e-04
2.17000000e-04 1.96700000e-04 1.87700000e-04 1.71600000e-04
1.64300000e-04 1.51300000e-04 1.45500000e-04 1.34800000e-04
1.29900000e-04 1.21100000e-04 1.17000000e-04 1.09500000e-04
1.06000000e-04 9.96600000e-05 9.67000000e-05 9.12100000e-05
8.86500000e-05 8.38800000e-05 8.16600000e-05 7.74900000e-05
7.55300000e-05 7.18600000e-05 7.01300000e-05 6.68800000e-05
6.53500000e-05 6.38700000e-05 6.24500000e-05 6.10800000e-05
5.97600000e-05 5.84800000e-05 5.72600000e-05 5.60700000e-05
5.49200000e-05 5.38100000e-05 5.27400000e-05 5.17100000e-05
5.07000000e-05 4.97300000e-05 4.92400000e-05 4.72200000e-05
4.35700000e-05 4.19100000e-05 3.88600000e-05 3.74700000e-05
3.49000000e-05 3.37200000e-05 3.15400000e-05 3.05300000e-05
2.86500000e-05 2.77800000e-05 2.61500000e-05 2.54000000e-05
2.39800000e-05 2.33200000e-05 2.20700000e-05 2.14900000e-05
2.03900000e-05 1.98700000e-05 1.89000000e-05 1.84300000e-05
1.75600000e-05 1.71500000e-05 1.63700000e-05 1.60000000e-05
1.53000000e-05 1.49700000e-05 1.43300000e-05 1.40300000e-05
1.34600000e-05 1.31800000e-05 1.26600000e-05 1.24100000e-05
1.19400000e-05 1.17100000e-05 1.12700000e-05 1.10600000e-05
1.06600000e-05 1.04700000e-05 1.01000000e-05 9.92500000e-06
9.58500000e-06 9.42200000e-06 9.10900000e-06 8.81100000e-06]
和 FILE_2 值:
[ 9.21500000e-07 1.68000000e-01 3.13000000e-01 4.47000000e-01
5.58000000e-01 8.37000000e-01 1.08000000e+00 1.67000000e+00
2.20000000e+00 3.31000000e+00 4.30000000e+00 6.53000000e+00
8.50000000e+00 1.29000000e+01 1.68000000e+01 2.03000000e+01
2.37000000e+01 2.68000000e+01 2.98000000e+01 3.27000000e+01
3.55000000e+01 3.82000000e+01 4.08000000e+01 4.34000000e+01
4.59000000e+01 4.83000000e+01 5.07000000e+01 5.31000000e+01
5.54000000e+01 5.77000000e+01 5.99000000e+01 6.21000000e+01
6.43000000e+01 6.65000000e+01 6.86000000e+01 7.07000000e+01
7.28000000e+01 7.49000000e+01 7.69000000e+01 8.09000000e+01
8.29000000e+01 8.68000000e+01 8.87000000e+01 9.25000000e+01
9.44000000e+01 9.81000000e+01 9.99000000e+01 1.04000000e+02
1.05000000e+02 1.09000000e+02 1.11000000e+02 1.14000000e+02
1.16000000e+02 1.19000000e+02 1.21000000e+02 1.24000000e+02
1.26000000e+02 1.29000000e+02 1.31000000e+02 1.34000000e+02
1.36000000e+02 1.39000000e+02 1.41000000e+02 1.44000000e+02
1.46000000e+02 1.47000000e+02 1.49000000e+02 1.50000000e+02
1.52000000e+02 1.53000000e+02 1.55000000e+02 1.57000000e+02
1.58000000e+02 1.60000000e+02 1.61000000e+02 1.63000000e+02
1.64000000e+02 1.66000000e+02 1.66000000e+02 1.69000000e+02
1.73000000e+02 1.75000000e+02 1.80000000e+02 1.82000000e+02
1.87000000e+02 1.89000000e+02 1.93000000e+02 1.96000000e+02
2.00000000e+02 2.02000000e+02 2.07000000e+02 2.09000000e+02
2.13000000e+02 2.15000000e+02 2.20000000e+02 2.22000000e+02
2.26000000e+02 2.28000000e+02 2.33000000e+02 2.35000000e+02
2.39000000e+02 2.41000000e+02 2.46000000e+02 2.48000000e+02
2.52000000e+02 2.54000000e+02 2.59000000e+02 2.61000000e+02
2.65000000e+02 2.67000000e+02 2.72000000e+02 2.74000000e+02
2.78000000e+02 2.80000000e+02 2.84000000e+02 2.86000000e+02
2.91000000e+02 2.93000000e+02 2.97000000e+02 2.99000000e+02
3.03000000e+02 3.06000000e+02 3.10000000e+02 3.14000000e+02]
和 FILE_3 值:
[ 2.59000000e+00 2.69000000e+00 2.92000000e+00 3.23000000e+00
3.54000000e+00 4.48000000e+00 5.41000000e+00 8.00000000e+00
1.06000000e+01 1.66000000e+01 2.27000000e+01 3.82000000e+01
5.37000000e+01 9.37000000e+01 1.34000000e+02 1.74000000e+02
2.14000000e+02 2.54000000e+02 2.94000000e+02 3.34000000e+02
3.74000000e+02 4.14000000e+02 4.54000000e+02 4.94000000e+02
5.34000000e+02 5.74000000e+02 6.14000000e+02 6.54000000e+02
6.94000000e+02 7.34000000e+02 7.74000000e+02 8.14000000e+02
8.54000000e+02 8.94000000e+02 9.34000000e+02 9.74000000e+02
1.01400000e+03 1.05400000e+03 1.09400000e+03 1.17400000e+03
1.21400000e+03 1.29400000e+03 1.33400000e+03 1.41400000e+03
1.45400000e+03 1.53400000e+03 1.57400000e+03 1.65400000e+03
1.69400000e+03 1.77400000e+03 1.81400000e+03 1.89400000e+03
1.93400000e+03 2.01400000e+03 2.05400000e+03 2.13400000e+03
2.17400000e+03 2.25400000e+03 2.29400000e+03 2.37400000e+03
2.41400000e+03 2.49400000e+03 2.53400000e+03 2.61400000e+03
2.65400000e+03 2.69400000e+03 2.73400000e+03 2.77400000e+03
2.81400000e+03 2.85400000e+03 2.89400000e+03 2.93400000e+03
2.97400000e+03 3.01400000e+03 3.05400000e+03 3.09400000e+03
3.13400000e+03 3.17400000e+03 3.19500000e+03 3.25500000e+03
3.37500000e+03 3.43500000e+03 3.55500000e+03 3.61500000e+03
3.73500000e+03 3.79500000e+03 3.91500000e+03 3.97500000e+03
4.09500000e+03 4.15500000e+03 4.27500000e+03 4.33500000e+03
4.45500000e+03 4.51500000e+03 4.63500000e+03 4.69500000e+03
4.81500000e+03 4.87500000e+03 4.99500000e+03 5.05500000e+03
5.17500000e+03 5.23500000e+03 5.35500000e+03 5.41500000e+03
5.53500000e+03 5.59500000e+03 5.71500000e+03 5.77500000e+03
5.89500000e+03 5.95500000e+03 6.07500000e+03 6.13500000e+03
6.25500000e+03 6.31500000e+03 6.43500000e+03 6.49500000e+03
6.61500000e+03 6.67500000e+03 6.79500000e+03 6.85500000e+03
6.97500000e+03 7.03500000e+03 7.15500000e+03 7.27500000e+03]
感谢您的帮助