python - 如何让 cmap 在三个 for 循环中以可迭代的方式工作?
问题描述
我正在为每个第三个变量的每个变量对构建一组图表,例如:
pressures = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
thicknesses = [0.5, 1.0, 1.5, 2.0]
velocities = [600.0, 700.0]
for velocity in velocities:
for thickness in thicknesses:
fig, ax = plt.subplots(1, 1)
cmap = plt.get_cmap('rainbow')
for pressure in pressures:
colors = iter(cmap(pressure/len(pressures)))
try:
ax.plot(x, y, label='{} mbar'.format(pressure), color=colors) #where (x, y) are variables decided earlier in the try loop
except TypeError:
continue
ax.plot()
ax.legend()
plt.show()
这用我想要的数据构建了一个图表,但我无法让颜色图工作。我试图让它在厚度/速度对的每次迭代中为每个压力显示相同的颜色。
解决方案
推荐阅读
- reactjs - 需要帮助使用 netlify 部署 React 应用程序
- c# - 如何在列表中拆分行?
- sql - 如何在codeigniter中的两个字段之间获取数据
- javascript - 在 php 项目中使用 nsfwjs 获取本地文件
- python - Python函数多次执行
- yii2 - 带有 AdminLTE 的 Yii2 中的模态表单不起作用
- wordpress - 错误:无法升级连接:找不到容器(“wordpress”)
- javafx - 不活动时如何加载到默认网站
- nginx - 如果VisualSVN设置为Nginx proxy_pass,会自动重定向到VisualSVN端口
- java - 如何在android中旋转位图?