Home > Software design >  Function to set axis labels only partially works, how do I get the axis labels to display as a funct
Function to set axis labels only partially works, how do I get the axis labels to display as a funct

Time:11-05

I want to write a function that will print the title and x and y labels. I managed to get the title to display but my code does not display the axis labels.

def title(t, y, x):
    return ax.set_title(t)
    ax.set_ylabel(y) 
    ax.set_xlabel(x)

I expect the code to display the Title, y-axis label, and x-axis label I enter the function like this:

title('LKJH', 'gg', 'ff')

I get the following chart instead Chart that is produced from code

CodePudding user response:

You were only returning set_title as a result the labels were not displaying.

Return all configs like this:

def title(t, y, x):
    return ax.set_title(t), ax.set_ylabel(y), ax.set_xlabel(x)

CodePudding user response:

In function title you have used return statement only for ax.set_title. The function is not considering the last 2 statements. You have to use comma (,) separator after every value if returning multiple values.

def title(t, y, x):
return (ax.set_title(t), ax.set_ylabel(y), ax.set_xlabel(x))
  • Related