使用轮廓绘制时尝试调整数据范围时得到奇怪的结果
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
plt.figure()
CS = plt.contourf(X, Y, Z, vmin = 0, vmax = 3)
plt.title('Simplest default with labels') …
Run Code Online (Sandbox Code Playgroud) 我的git项目包含我不想被推送到存储库的.cas文件.我因此添加了这条线
**/*.cas
Run Code Online (Sandbox Code Playgroud)
到我的.gitignore
文件但.cas
文件仍会出现git status
.阅读了许多其他帖子后,我检查了.gitignore
条目没有尾随空格,并且它们确实有unix行更改说明符.
然后我按照这里的建议运行以下命令: .gitignore不起作用
git rm -r --cached .
git add .
Run Code Online (Sandbox Code Playgroud)
但是徒劳!git status
仍然报告例如
new file: calc/2_preliminary/1_CFD/7_Calc_Fluent/03_stationary_vof_stationary/mesh_04/run_10000.cas
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我真的很感激.
.gitignore
文件内容:
calc/
0_BSc_Alvarez/
calc/0_Test/
documentation/Tutorial_Fluent/
literature/
thunderbird/
**/.idea/
.zim
**/ND800_*
**/*.cas
**/*.dat
**/*.cdat
**/*.uns
**/*.msh
**/*.bak
Run Code Online (Sandbox Code Playgroud)
git版本是1.7.1
我打算在一个单独的图中为已经在另一个图中绘制的元素创建一个新的图例。
这里建议使用以下解决方案,但它失败了PolyCollections
,例如,由fill_between
.
doesntwork=True
import matplotlib.pyplot as plt
# Here I am creating a figure and saving it to a png file
fig, ax = plt.subplots()
ax.plot( [0,1], [1,0], label='item 1')
if doesntwork:
ax.fill_between([0,1], [2,1], y2=[1.5,0.5], label='item 2')
ax.legend()
fig.savefig('image.png')
# Here I want the legend stored in a separate png file ...
# ... create a new figure for this purpose
fig_leg = plt.figure(figsize=(1.5, 0.8))
ax_leg = fig_leg.add_subplot(111)
# ... draw the legend
ax_leg.legend(*ax.get_legend_handles_labels(), loc='center') …
Run Code Online (Sandbox Code Playgroud) 我有两个数组A
和B
。现在让它们都是一维的。
对于 中的每个元素,我需要与 中的元素最匹配的元素A
的索引。B
A
我可以使用列表表达式来解决这个问题
import numpy as np
A = np.array([ 1, 3, 1, 5 ])
B = np.array([ 1.1, 2.1, 3.1, 4.1, 5.1, 6.1 ])
indices = np.array([ np.argmin(np.abs(B-a)) for a in A ])
print(indices) # prints [0 2 0 4]
print(B[indices]) # prints [1.1 3.1 1.1 5.1]
Run Code Online (Sandbox Code Playgroud)
但这种方法对于巨大的数组来说确实很慢。
我想知道是否有更快的方法利用优化的 numpy 函数。
python ×3
matplotlib ×2
arrays ×1
git ×1
gitignore ×1
indexing ×1
numpy ×1
performance ×1
plot ×1