1 year ago

#1512

test-img

Yair hadad

ticks for matplotlib twinx axes not current

Hey I have issue with the matplotlib twinx axes, I have 2 plot with the same X ticks, But when I set them both in the same plot with twinx I get wrong plot.

  • The first plot data:

    Potential_Date_month
    1     0.033616
    2     0.033256
    3     0.026578
    4     0.029624
    5     0.026549
    6     0.029654
    7     0.031489
    8     0.025707
    9     0.030870
    10    0.023068
    11    0.042049
    12    0.056363
    Name: target, dtype: int64
    
    
    

and plot looks:

enter image description here

  • The secand plot data:

    Potential_Date_month
    1      7318
    2      6886
    3     18737
    4     11342
    5     19624
    6     22324
    7     18451
    8     15988
    9      5928
    10     5462
    11    10250
    12     5571
    Name: target, dtype: int64```
    
    
    

enter image description here

But when I use the next code, something get wrong:

    fig,ax1 = plt.subplots()
    ax2 = ax1.twinx()

    series1.plot(ax = ax1,color = 'blue')
    series2.plot.bar(ax = ax2, color = 'green', alpha = 0.5)

    plt.show()

plot:

s

you can see the line plot isn't staring from one ticks, it start with 2. I'm not sure what cause this issue,

Thank you.

python

matplotlib

twinx

0 Answers

Your Answer

Accepted video resources