1
我試圖在paper中得到數字5,但我無法生成兩個陰影區域,指示1 kcal/mol和2 kcal/mol的誤差。每個陰影區域必須與紙張顏色不同。我怎樣才能做到這一點?如何使用matplotlib生成陰影區域
我的代碼:
#!/usr/bin/python
import numpy as np
import pylab as plot
import matplotlib.pyplot as plt
import numpy, scipy, pylab, random
from matplotlib.ticker import MultipleLocator
import matplotlib as mpl
from matplotlib.ticker import MaxNLocator
color = "#252525"
gray = "#777777"
with open("input.txt", "r") as f:
x=[]
y=[]
z=[]
for line in f:
if not line.strip() or line.startswith('@') or line.startswith('#'): continue
row = line.split()
x.append(float(row[0]))
y.append(float(row[1]))
z.append(float(row[2]))
fig = plt.figure(figsize=(3.2,2.2), dpi=300)
ax = plt.subplot(111)
plt.xlim(-2, -12)
plt.ylim(-2, -12)
ax.xaxis.set_major_locator(MaxNLocator(6))
ax.yaxis.set_major_locator(MaxNLocator(6))
ax.xaxis.set_minor_locator(MultipleLocator(1))
ax.yaxis.set_minor_locator(MultipleLocator(1))
plt.plot(x,y,'o',color="black", ms=3, mec="black")
plt.plot(x,z, color='gray' , linestyle = "dashed", dashes=(2,2))
plt.xlabel('Experimental (kcal/mol)', fontsize=8)
plt.ylabel('Predicted (kcal/mol)', fontsize=8)
for axis in ['top','bottom','left','right']:
ax.spines[axis].set_linewidth(0.5)
plt.subplots_adjust(top=0.95)
plt.subplots_adjust(bottom=0.18)
plt.subplots_adjust(left=0.14)
plt.subplots_adjust(right=0.95)
plt.tick_params(axis='both', which='major', labelsize=7)
plt.tick_params(axis='both', which='minor', labelsize=0)
plt.savefig("output.png", dpi=300)
輸入文件:
-2 -2.0 -2
-3 -3.5 -3
-4 -5.0 -4
-5 -7.0 -5
-6 -6.0 -6
-8 -10.1 -8
-10 -10.0 -10
-12 -12.0 -12
獲得輸出: