Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 写入函数:plt的绘图栏,带有plt.title()的可选参数_Python_Function_Matplotlib_Python 3.5 - Fatal编程技术网

Python 写入函数:plt的绘图栏,带有plt.title()的可选参数

Python 写入函数:plt的绘图栏,带有plt.title()的可选参数,python,function,matplotlib,python-3.5,Python,Function,Matplotlib,Python 3.5,您不能简单地将任意参数放入不需要它们的函数中 需要一个字符串作为输入 可以使用format方法生成字符串 def plot_coexpression(new, gene1='', gene2='', gene3='', gene4='', gene5='', gene6=''): X, Y = zip(*new) import seaborn as sns sns.set() import matplotlib.pyplot as plt %matplo

您不能简单地将任意参数放入不需要它们的函数中

需要一个字符串作为输入

可以使用format方法生成字符串

def plot_coexpression(new, gene1='', gene2='', gene3='', gene4='', gene5='', gene6=''):
    X, Y = zip(*new)
    import seaborn as sns
    sns.set()
    import matplotlib.pyplot as plt 
    %matplotlib inline
    plt.figure(figsize = (20, 10))
    plt.title('Genes most commonly co-expressed with' gene1="axin", gene2="lef", gene3="lgr", gene4="nkd", gene5="", gene6="", fontsize=40)

    ax = plt.bar(range(len(X)), Y, 0.6, align='center', tick_label = X, color="green") 
    ax = plt.xticks(rotation=90)


  File "<ipython-input-3-a3383d66ce8c>", line 8
    plt.title('Genes most commonly co-expressed with' gene1="axin", gene2="lef", gene3="lgr", gene4="nkd", gene5="", gene6="", fontsize=40)
def plot_coexpression(new, gene1=None, gene2=None, gene3=None, gene4=None, gene5=None, gene6=None):
    X, Y = zip(*new)
    plt.figure(figsize = (20, 10))
    plt.title('Genes most commonly co-expressed with' gene1, gene2, gene3, gene4, gene5, gene6,"'", fontsize=40)
    ax = plt.bar(range(len(X)), Y, 0.6, align='center', tick_label = X, color="green") 
    ax = plt.xticks(rotation=90)
mytitle = "This is my title, containing {gene1}".format(gene1="axin")
plt.title(mytitle)