如何在r曲线的x轴上绘制实际年份而不是0,1,2 ...... 20年

时间:2016-01-17 07:03:53

标签: r

我是R的新手。如果我在错误的论坛中提出我的问题,请告诉我正确的链接。我正在从netcdf文件中读取和提取数据。我想绘制实际年份,即1980,1981,...... 1999年x轴而不是0,1,... 20。我尝试在绘图中使用xrange或xaxt和axis命令更改范围但不能这样做。另外,我想绘制1980-1999之间的线,但是http://i.stack.imgur.com/z8sEL.png该线在1999年之后继续(见图)我试过自从过去7天没有任何成功,无法集中精力继续前进。我复制了部分代码和图片。我将感谢你的帮助。谢谢。

import random


Generate_Number_CHOICE = 1
Average_Calculate_CHOICE = 2
Display_Grades_CHOICE = 3
Display_Failing_Marks_CHOICE = 4
QUIT_CHOICE = 5

def display_menu():
    print('        MENU')
    print('1) Enter Your Marks')
    print('2) Get Your Average')
    print('3) Display Your Grades')
    print('4) Display Failin Marks')
    print('5) Quit')


def generate_number():

    numbers = random.sample(range(1 ,100),30)
    print(numbers)
    return numbers





def average_calculate(numbers):
    total = sum(numbers)
    average = total // 30
    print('------------------------------------')
    print('Your Average is:', average)
    print(" ")




def display_grades(numbers):

    for mark in(numbers):
        if mark  >= 90:
         print('------------------------------------')
         print('A+',mark)
        elif mark  >= 80:
         print('------------------------------------')
         print('B+',mark )
        elif mark  >= 70:
         print('------------------------------------')
         print('C+',mark)
        elif mark  >= 60:
         print('------------------------------------')
         print('D+',mark)
        else:
         print('------------------------------------')
         print('F',mark)

    return mark
    return courses_Name


def display_failing(numbers):
    for number in (numbers):
            if number <= 59:
             print('------------------------------------')
             print("you Fail in",number)
             print(" ")


def main():
        infile = open('philosophers.txt', 'w')

        choice = 0
        while choice != QUIT_CHOICE:

            display_menu()

            choice = int(input('Enter your choice: '))

            if choice == Generate_Number_CHOICE:
                numbers = generate_number()



            elif choice == Average_Calculate_CHOICE:

                average_calculate(numbers)

            elif choice == Display_Grades_CHOICE:

                mark = display_grades(numbers)


            elif choice == Display_Failing_Marks_CHOICE:

                display_failing(numbers)

            elif choice == QUIT_CHOICE:

                print('Exiting the program...')

            else:

                print('Error: invalid selection.')

main()

1 个答案:

答案 0 :(得分:0)

一种方法是移除plot中的轴,然后再重新添加。 pretty可以帮助您自动化标签展示位置。将所有轴选项解析为axis行。

plot(an_time, varX_year, main = heading, type="l", ylim = c(0,yrange)
     ,xlab = "Year", ylab = unity, col = "red", cex.lab = 1.5,
     ,axes = FALSE)
axis(1, at = pretty(an_time), labels = pretty(an_time) + 1980, cex.axis=1.5)
axis(2, cex.axis=1.5,)
box()

请谨慎使用此方法,因为您只需更改标签。 我想的另一种解决方法可能只是将1980年添加到年矢量,即

an_time <- an_time + 1980