# Plotting a cumulative frequency line on a histogram with second y axis

**URL:** <https://discourse.julialang.org/t/plotting-a-cumulative-frequency-line-on-a-histogram-with-second-y-axis/63675>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [June 28, 2021, 6:24am UTC](https://discourse.julialang.org/t/plotting-a-cumulative-frequency-line-on-a-histogram-with-second-y-axis/63675 "2021-06-28T06:24:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leejm516](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leejm516/32/8219_2.png) [@leejm516](https://discourse.julialang.org/u/leejm516)\
**Post date:** [June 28, 2021, 6:24am UTC](https://discourse.julialang.org/t/plotting-a-cumulative-frequency-line-on-a-histogram-with-second-y-axis/63675/1 "2021-06-28T06:24:59Z")

</div>

Dear all:

I am struggling with plotting a histogram with a cumulative frequency line overlaid.  
I want to use `twinx()` to display the second y axis, but my code does not work.

```julia
using Plots

# some doing for data
scores = floor.(Int64, rand(10)*100)

freq = fit(Histogram, english_scores, 0:10:100)
rel_freq = freq.weights ./ sum(freq.weights)
cum_reql_freq = cumsum(rel_freq)

# plot
histogram(scores, bins = 0:10:100)
subplt = twinx()
plot!(subplt,5:10:95 , cum_reql_freq)

```

This only gives (both in GR and PyPlot backends):  
 ![test](https://global.discourse-cdn.com/julialang/original/3X/8/4/84933e1daf559bc8627ef98f16711b66ea8ade8b.png)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 28, 2021, 9:44am UTC](https://discourse.julialang.org/t/plotting-a-cumulative-frequency-line-on-a-histogram-with-second-y-axis/63675/2 "2021-06-28T09:44:31Z")

</div>

Looks like a bug in Plots to me, a simpler MWE is

```julia
using Plots

histogram(rand(50))

plot!(twinx(), rand(50))

```

---

<div class="post-metadata">

**Author:** ![tai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tai/32/5799_2.png) [@tai](https://discourse.julialang.org/u/tai)\
**Post date:** [July 6, 2021, 6:33am UTC](https://discourse.julialang.org/t/plotting-a-cumulative-frequency-line-on-a-histogram-with-second-y-axis/63675/3 "2021-07-06T06:33:04Z")

</div>

I’m also hit by this issue and can only get blank plots just like the original poster when I use twinx().  
Is there any workaround for this? Downgrade Plots.jl?

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [July 6, 2021, 8:36am UTC](https://discourse.julialang.org/t/plotting-a-cumulative-frequency-line-on-a-histogram-with-second-y-axis/63675/4 "2021-07-06T08:36:55Z")

</div>

until this is fixed. Use Plots 1.16.5

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [July 6, 2021, 11:46am UTC](https://discourse.julialang.org/t/plotting-a-cumulative-frequency-line-on-a-histogram-with-second-y-axis/63675/5 "2021-07-06T11:46:31Z")

</div>

This was fixed in `Plots 1.17.0`
