Home > Software design >  I am getting error when trying to plot two seperate lines in seaborn
I am getting error when trying to plot two seperate lines in seaborn

Time:10-27

I wish to write two different lines on heatmap. My code is

lines = [0,10,300,500,2560, 34500]
     with sns.axes_style("white"):
            f, ax = plt.subplots(figsize=(50, 50))
            ax = sns.heatmap(X)
            ax.axvline(4000, *ax.get_ylim(), ymin = lines[0], ymax = lines[4], lw = 8.0,  color = 'red')
            ax.axvline(4000, *ax.get_ylim(), ymin = lines[5], lw = 8.0,  color = 'green')

and I get an error like

TypeError: axvline() got multiple values for argument 'ymin'.

What does that mean?

CodePudding user response:

According to the documentation,, axvline's signature is

axvline(x=0, ymin=0, ymax=1, **kwargs)

so when you do

ax.axvline(4000, *ax.get_ylim(), ymin = lines[0], ymax = lines[4],

(and get_ylim() returns a 2-tuple), you're passing ymin and ymax twice.

You'll need to either

  • not use *ax.get_ylim(), or
  • not use ymin and ymax separately.

CodePudding user response:

Okay there is a work around to the question. Commenter above mentioned that y axis should always take a number between 0 and 1.

So we can do a work around with percentage.

lines = [0,10,300,500,2560, 34500]
p_1 = lines[4]/lines[-1]
p_2 = 1
     with sns.axes_style("white"):
            f, ax = plt.subplots(figsize=(50, 50))
            ax = sns.heatmap(X)
            ax.axvline(4000, *ax.get_ylim(), ymin = 1-p1, ymax = p2, lw = 8.0,  color = 'red')
            ax.axvline(4000, *ax.get_ylim(), ymin = 0,ymax = 1-p1, lw = 8.0,  color = 'green')
  • Related