OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Custom colors for median segmests in plotnine geom_boxplot

  • Thread starter Thread starter ash
  • Start date Start date
A

ash

Guest
I want to draw the median segments in geom_boxplot() with custom colors. I found a solution for R-ggplot2 with gg_build() which provides x, xend, y, yend inputs for geom_segment() to overlay the median segments on the boxplot.

I couldn't find gg_build() equivalent functionality in plotnine, so my approach is to construct a new dataframe which calculates these 4 values for each group, needed by geom_segment.

To that end, I know how to get y and yend for each group - these values are the group medians. However, not clear on how to calculate x and xend? Since I need to find a x-value for each group (for my use-case, groups names are str type). Additionally, I also require the box-width used in geom_boxplot().

Any suggestions on how to extract/calculate those?

Thanks!
<p>I want to draw the median segments in <code>geom_boxplot()</code> with custom colors. I found a <a href="https://stackoverflow.com/questions/64289509/change-color-of-median-line-ggplot-geom-boxplot">solution</a> for R-ggplot2 with <code>gg_build()</code> which provides <code>x</code>, <code>xend</code>, <code>y</code>, <code>yend</code> inputs for <code>geom_segment()</code> to overlay the median segments on the boxplot.</p>
<p>I couldn't find <code>gg_build()</code> equivalent functionality in <strong>plotnine</strong>, so my approach is to construct a new dataframe which calculates these 4 values for each group, needed by <code>geom_segment</code>.</p>
<p>To that end, I know how to get <code>y</code> and <code>yend</code> for each group - these values are the group medians. However, not clear on how to calculate <code>x</code> and <code>xend</code>? Since I need to find a x-value for each group (for my use-case, groups names are <code>str</code> type). Additionally, I also require the box-width used in <code>geom_boxplot()</code>.</p>
<p>Any suggestions on how to extract/calculate those?</p>
<p>Thanks!</p>
 

Latest posts

I
Replies
0
Views
1
Isaac P. Liu
I
U
Replies
0
Views
1
user3658366
U
G
Replies
0
Views
1
Giampaolo Levorato
G
M
Replies
0
Views
1
Marcelo Rodrigo Nascimento
M
Top