【发布时间】:2021-10-30 01:21:15
【问题描述】:
这是我的代码
import matplotlib.pyplot as plt
import numpy as np
#Declaring data
year = []
relative_recurrence = []
#Open data file
f = open('relative recurrence plot.txt','r')
for row in f:
row = row.split(' ')
year.append(int(row[0]))
relative_recurrence.append(float(row[1]))
#Plot the graph
plt.bar(year, relative_recurrence,color = 'grey', label = 'HILDCAAS', edgecolor='black')
plt.xticks(np.arange(min(year), max(year) + 1, 5))
# Label for x-axis
plt.xlabel("YEAR")
# Label for y-axis
plt.ylabel("Relative Occurence")
plt.savefig('recurrence plot.png')
plt.show()
我想在这里做两处改变。 首先是:在 x 轴上,范围是 1975 到 2018 年,我想在 x 轴上显示每一年的标记,而不是年份。 第二个是: 对于 x 的某些值; y 为零,因此对于零值,我想在 x 轴附近添加标签“G”。
请告诉有用的代码添加到这个程序。 数据是: 1975 年 0.916 1976 0 1977 0 1978 年 1 1979 年 0.916 1980 0 1981 0 1982 0.75 1983 0.9 1984 1.125 1985 1.5 1986 年 0.416 1987 1 1988 0 1989 0 1990 1 1991 0 1992 0.4 1993 年 0.416 1994 0.7 1995 0.5 1996 0.571 1997 年 0.285 1998 1 1999 0.5 2000 0.545 2001 1 2002 年 0.333 2003 1.5 2004 年 0.58 2005 年 0.454 2006 年 0.375 2007 年 0.444 2008 0 2009 0 2010 0 2011 2 2012 1 2013 1 2014 1 2015 2 2016 2 2017 1.42
【问题讨论】:
-
非常感谢!!!!我对此持负面看法。所以我把它删了。
标签: python pandas numpy matplotlib