Answers.Body: <p>I'm not familiar with seaborn, but I'd guess from the error that there's at least one text value inside the <code>Synergy_percent</code> field that is encouraging the rest of the values to text. Either that, or spaces in the input file are messing up the parsing of the columns.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-18T12:55:04.120Z
Answers.LastActivityDate: 2022-04-18T12:55:04.120Z
Answers.UserDisplayName: gringer
Answers.Body: <p>Very quickly because I'm not around.</p>
  <p>I think I know what's going on, but don't have enough time to figure the df. The key thing is <code>seaborn</code> needs to know where columns are <code>x</code> and which are <code>y</code> ... <em>within the data frame</em> . This information appears missing and the OP used <code>y='title', x='title</code> without reference to the dataframe. I'm pretty certain thats the bug here.</p>
  <pre><code>import seaborn as sns
  import matplotlib.pyplot as plt
  
  plot = sns.boxplot(
      color='white',
      y=synergy_df[&quot;Synergy_percent&quot;], 
      x=synergy_df[&quot;Min PPI distance&quot;] 
  );
  plt.show()
  </code></pre>
  <p>Alternative, which seems more what the OP wants ...</p>
  <pre><code>import seaborn as sns
  import matplotlib.pyplot as plt
  
  plot = sns.boxplot(
      color='white',
      # use your orientation command here
      x=synergy_df[&quot;Synergy_percent&quot;], 
      y=synergy_df[&quot;Min PPI distance&quot;] 
  );
  plt.show()
  </code></pre>
  <p><strong>Blurb</strong> Normally the x-axis is the discrete boundary whilst the y-axis is continuous. In you example the x-axis feels like the continuous variable and you are producing a rotated boxplot - thats perfectly fine and seabourn will do that however its  good to get it working first before rotating the axes.</p>
  <p><strong>Final</strong> The orientation of the dataframe might possibly be an issue, not sure unless its tried.</p>
  <hr />
  <p>If there's a formatting issue the only trick I know is</p>
  <pre><code> plot = sis.boxplot(
   .... # same old
   dodge=True,
   );
  </code></pre>
  <p>I don't know beyond, e.g. imposing percentile ranges onto a boxplot.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-18T14:27:56.607Z
Answers.Text: Well its good its working. Could you try `dodge=True`. ?? What I think you want is to tweak the 'box and whiskers' of the boxplot - which I'd have to look up. The other possibility (which I don't think you want) is to make 4 boxplots within the range specified. This is last point is about `pandas` filtering and would be outside seaborn. I'm pretty certain you just need a simple tweak within `boxplot` method. However, beyond the `dodge` trick I dunno, but `dodge` does clean stuff up.
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-19T03:19:01.223Z
Answers.Text: Good to know; I guess that means `data=X` doesn't have the same effect in seaborn as it does in R.
Answers.UserDisplayName: gringer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-18T14:03:44.603Z
Answers.LastActivityDate: 2022-04-18T14:33:04.663Z
Answers.LastEditDate: 2022-04-18T14:33:04.663Z
Answers.UserDisplayName: M__
Body: <p>I am trying to plot a box plot with <a href="https://seaborn.pydata.org/generated/seaborn.boxplot.html" rel="nofollow noreferrer">seaborn</a> with the following code</p>
  <pre><code>plot = sns.boxplot(
      y='Min PPI distance',
      x='Synergy_percent',
      color='white',
      orient=&quot;h&quot;,
      data=synergy_df
  )
  plot.set(
      xlabel='Synergy (%)',
      ylabel='Min. distance',
  );
  </code></pre>
  <p>The data <code>synergy_df</code> looks like</p>
  <pre><code>    Combination Min PPI distance    Synergy_percent
  0   1003- Camptothecin &amp; 1011- Navitoclax   2.0 22.2
  1   1003- Camptothecin &amp; 1017- Olaparib 2.0 6.4
  2   1003- Camptothecin &amp; 1022- AZD7762  2.0 40.4
  3   1003- Camptothecin &amp; 1025- SB216763 3.0 2.1
  4   1003- Camptothecin &amp; 1032- Afatinib 3.0 2.2
  </code></pre>
  <p>After running the above code I am getting the error
  <code>TypeError: Horizontal orientation requires numeric `x` variable.</code>
  I want to add that Synergy_percent column has many zero values and about 1500 rows; I haven't tried it with a smaller number of rows.</p>
  <p>I think the reason for the error is the wide range in the synergy_percent values. The range is between 0 to 86.7. If I use xlim here what range should I use to divide the x-axis in 4 quarters (0-25-50-100)?</p>
  <p><strong>Background</strong> Seaborn is a Python library for more complex graph plotting than the commonly used <code>matplotlib</code> and is often used for boxplots and heatmaps usually using a <code>pandas</code> dataframe. The official documents are described <a href="https://seaborn.pydata.org/generated/seaborn.boxplot.html" rel="nofollow noreferrer">here</a>.</p>
  
Tags: <visualization><python><graphs>
Title: Error in seaborn plot " Horizontal orientation requires numeric `x` variable"
ThreadText: # Error in seaborn plot " Horizontal orientation requires numeric `x` variable"
  
  (Asked by: username_0 on 2022-04-18)
  
  I am trying to plot a box plot with [seaborn](https://seaborn.pydata.org/generated/seaborn.boxplot.html) with the following code
  
  ```
  plot = sns.boxplot(
      y='Min PPI distance',
      x='Synergy_percent',
      color='white',
      orient="h",
      data=synergy_df
  )
  plot.set(
      xlabel='Synergy (%)',
      ylabel='Min. distance',
  );
  
  ```
  
  The data `synergy_df` looks like
  
  ```
      Combination Min PPI distance    Synergy_percent
  0   1003- Camptothecin & 1011- Navitoclax   2.0 22.2
  1   1003- Camptothecin & 1017- Olaparib 2.0 6.4
  2   1003- Camptothecin & 1022- AZD7762  2.0 40.4
  3   1003- Camptothecin & 1025- SB216763 3.0 2.1
  4   1003- Camptothecin & 1032- Afatinib 3.0 2.2
  
  ```
  
  After running the above code I am getting the error
  `TypeError: Horizontal orientation requires numeric `x` variable.`
  I want to add that Synergy\_percent column has many zero values and about 1500 rows; I haven't tried it with a smaller number of rows.
  
  I think the reason for the error is the wide range in the synergy\_percent values. The range is between 0 to 86.7. If I use xlim here what range should I use to divide the x-axis in 4 quarters (0-25-50-100)?
  
  **Background** Seaborn is a Python library for more complex graph plotting than the commonly used `matplotlib` and is often used for boxplots and heatmaps usually using a `pandas` dataframe. The official documents are described [here](https://seaborn.pydata.org/generated/seaborn.boxplot.html).
  
  **Tags:** visualization, python, graphs
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2022-04-18. Score: 3 | Accepted answer
  
  Very quickly because I'm not around.
  
  I think I know what's going on, but don't have enough time to figure the df. The key thing is `seaborn` needs to know where columns are `x` and which are `y` ... *within the data frame* . This information appears missing and the OP used `y='title', x='title` without reference to the dataframe. I'm pretty certain thats the bug here.
  
  ```
  import seaborn as sns
  import matplotlib.pyplot as plt
  
  plot = sns.boxplot(
      color='white',
      y=synergy_df["Synergy_percent"], 
      x=synergy_df["Min PPI distance"] 
  );
  plt.show()
  
  ```
  
  Alternative, which seems more what the OP wants ...
  
  ```
  import seaborn as sns
  import matplotlib.pyplot as plt
  
  plot = sns.boxplot(
      color='white',
      # use your orientation command here
      x=synergy_df["Synergy_percent"], 
      y=synergy_df["Min PPI distance"] 
  );
  plt.show()
  
  ```
  
  **Blurb** Normally the x-axis is the discrete boundary whilst the y-axis is continuous. In you example the x-axis feels like the continuous variable and you are producing a rotated boxplot - thats perfectly fine and seabourn will do that however its good to get it working first before rotating the axes.
  
  **Final** The orientation of the dataframe might possibly be an issue, not sure unless its tried.
  
  ---
  
  If there's a formatting issue the only trick I know is
  
  ```
   plot = sis.boxplot(
   .... # same old
   dodge=True,
   );
  
  ```
  
  I don't know beyond, e.g. imposing percentile ranges onto a boxplot.
  
  > **Comments:**
  > **username_2**: Well its good its working. Could you try `dodge=True`. ?? What I think you want is to tweak the 'box and whiskers' of the boxplot - which I'd have to look up. The other possibility (which I don't think you want) is to make 4 boxplots within the range specified. This is last point is about `pandas` filtering and would be outside seaborn. I'm pretty certain you just need a simple tweak within `boxplot` method. However, beyond the `dodge` trick I dunno, but `dodge` does clean stuff up.  
  > **username_1**: Good to know; I guess that means `data=X` doesn't have the same effect in seaborn as it does in R.  
  
  ---
  
  ### Answer by username_1 on 2022-04-18. Score: 1
  
  I'm not familiar with seaborn, but I'd guess from the error that there's at least one text value inside the `Synergy_percent` field that is encouraging the rest of the values to text. Either that, or spaces in the input file are messing up the parsing of the columns.
  
  
  ---
  
  