python - 如何使用 for 循环绘制变量?
问题描述
我正在尝试编写一个代码,在一个图中创建一组 20 个图(每个“区域”一个)。为此,我使用了命令fig,ax = plt.subplots
和for loop
. 但是,每次运行代码时,计算机都会返回一个 5x4 空图加上每个区域的图,就好像我手动运行了 20 次代码一样。
你能帮我吗?由于我是 Python 新手,如果您能简要解释一下冲突是什么,我也将不胜感激。代码如下所示:
fig, ax = plt.subplots(5,4,frameon=False,figsize=(22,22))
fig.tight_layout
#plt.subplots_adjust(left=0.1,bottom=0.1,right=0.90,top=0.90,wspace=0.3,hspace=1)
sns.set_style('white')
for tractName in tractCount:
currentTract=df.query("tract == @tractName")
coeffType1CurrentTract=coeffType1.query('tract == @tractName')
coeffType2CurrentTract=coeffType2.query('tract == @tractName')
sns.set(font_scale = 2)
sns.set_style('white')
ax = sns.relplot(data=currentTract, x='node', y='coeff', hue='coeffType', kind='line',palette='Blues', col = 'tract', linewidth=1) #I have changed the palette colour from 'crest' to 'Blues' as my computer didn't recognise that colour
ax = plt.fill_between(coeffType1CurrentTract["node"], coeffType1CurrentTract['coeff']-coeffType1CurrentTract['se'], coeffType1CurrentTract['coeff']+coeffType1CurrentTract['se'], color='blue',alpha=0.2)
ax = plt.fill_between(coeffType2CurrentTract["node"], coeffType2CurrentTract['coeff']-coeffType2CurrentTract['se'], coeffType2CurrentTract['coeff']+coeffType2CurrentTract['se'], color='blue',alpha=0.2)
#fig.savefig('isPremi_md.png')
plt.show()
解决方案
推荐阅读
- amazon-s3 - 如何将 S3 docker store 用于 ECS?
- c# - 即使安装了应用程序也找不到预览处理程序
- firebase - 请求的资源上不存在“Access-Control-Allow-Origin”标头 | Firebase Cloud Firestore - Java - 离子
- c# - JsonConvert.DeserializeAnonymousType 绕过数组
- java - Java 并发,同步。我在一个方法中增加两个变量,但它们是不同的
- r - 在 r(不是 ggplot)中使用 barplot 绘图时从列中删除某种数据
- c++ - 如何使用 ofstream c++ 替换文本文件中的特定值?
- algorithm - 棋盘上的骑士-最短路径
- python - 如何在pyspark中使用map进行rest api调用
- java - 如何在 Java 中创建对 MongoDB 没有价值的文档