【发布时间】:2018-05-13 14:43:40
【问题描述】:
我有一个代码可以单独或同时运行两个图形。问题是当它们同时运行时。它们都没有正确显示。我尝试使用plt.subplotlib,但没有帮助。
这是代码
import numpy as np
import matplotlib.pyplot as plt
Choice = input('Which figure do you want to run: \n *for Fig.1 , write 1 \n *for Fig.2, write 2 \n *for both , write b \n--> ')
Etta_Source={};Etta_Source1={};QKN_Source={}
for E_So in [100,200,400,800,600,1000]:
for Temp in range(0,110,10):
Etta = 0.8 - ((3.41*Temp)+(0.014*(Temp)**2))/E_So
if Choice == '1' or Choice == 'b':
QKN_Source[Temp] = Etta*2.3*E_So
Etta_Source[Temp] = Etta
if E_So == 1000 and (Choice == '2' or Choice == 'b'):
Etta_Source1[Temp]=Etta
if Choice == '1' or Choice == 'b':
plt.figure(1)
plt.plot(QKN_Source.keys(),QKN_Source.values(),label='D = %s'%E_So)
QKN_Source.clear()
if Choice == '2' or Choice == 'b':
plt.figure(2)
plt.plot(Etta_Source.keys(),Etta_Source.values(),label='C= %s'%E_So)
Etta_Source.clear()
if Choice == '2' or Choice == 'b':
plt.axhline(0.8,ls='-.',color='skyblue')
plt.fill_between(Etta_Source1.keys(),Etta_Source1.values(),0.8,facecolor='wheat')
plt.axhspan(0.8,1.0,alpha=0.5, color='c')
plt.axis([0,100,0,1])
plt.text(50, 0.9, r'Area 1',fontsize=14,fontweight='bold')
plt.text(80, 0.6, r'Area 2',fontsize=14,fontweight='bold')
plt.yticks(np.arange(0,1.1,0.1))
plt.ylabel('W',fontsize=14)
if Choice == '1' or Choice == 'b':
plt.axis([0,100,0,2000])
plt.ylabel('V',fontsize=14)
plt.grid(True)
plt.title('Results',color='black',fontsize=15,fontweight='bold')
plt.xticks(range(0,110,10),fontsize=14)
plt.xlabel(r'$\beta_a + \alpha_a$',fontsize=14)
plt.tight_layout()
plt.legend(loc=1)
plt.show()
【问题讨论】:
-
出现问题时只需输入 b 即可显示两个数字
-
我猜你需要输入 'b' 而不是 b 才能工作
-
只是字母 b
-
plt.axis([0,100,0,2000])将缩放应用于第二个数字,因为您没有指定轴。这种效果的另一个标志是y轴标签“V”现在在第二个图中,因为这个命令是在第一个图生成之后执行的。
标签: python python-3.x matplotlib plot figure