0

I have the following dataframe:

------------------------------------------------------------
| Month | low_temp | high_temp |   Wages        | Extreme  |
------------------------------------------------------------
| Jan   |    0     |    3      |    -0.42       | 1000     |
------------------------------------------------------------
| Jan   |    1     |    3      |     0.56       | 3000     |
------------------------------------------------------------
| Feb   |    -1    |    2      |     -0.61      | 2000     |
------------------------------------------------------------
| Feb   |    0     |    1      |     0.36       | 3500     |
-------------------------------------------------------------
| Mar   |    1.5   |    4      |    -0.25       | 3000     |
-------------------------------------------------------------
| Mar   |    2     |    5      |     0.75       | 4000     |
-------------------------------------------------------------
| Apr   |    3     |    5      |    -0.55        | 3000    |
------------------------------------------------------------
| Apr   |    3.25  |    4      |    0.24         | 6000    |
-------------------------------------------------------------

What I'm trying to do is create one continuous plot with two x axes.

So, it would have the follow features:

one y-axis for low_temp and high_temp.

two lines: low_temp, high_temp

x_axis1 (the important one): Extreme

x_axis2 (below or above the x_axis1, lines up with it but isn't used to plot anything): Wages

And then, for each Month, create this chart and then string it together horizontally

so it ends up:

y  --------------------------
   |     |     |     |     |
   | jan | feb | mar | apr |
  -------------------------
x axis 1
x axis 2

This is my code attempt but it causes the x-axis to not be in line at all!

for index, month in enumerate(Months):
    a = df[df['Month']==month].sort_values(by='Extreme')
    x = a['Extreme']
    y_1 = a['low_temp']
    y_2 = a['high_temp']


    plt.subplot(1,4,index+1)

    plt.plot(x,y_1,'bo-')
    plt.plot(x,y_2, 'ro-')
    plt.xticks(a.Wages)
    plt.title(month)
    plt.show()

The charts also appear in a vertical line so they aren't horizontally contiguous.

Any help is very much appreciated! thanks!

  • 1
    I think you'd get more help if you were to draw (using paint, or even on a piece of paper and taking a photo) the desired output instead of the ascii-art you provided. I honestly cannot figure out what you are trying to describe. – Diziet Asahi Oct 02 '19 at 20:33
  • 1
    Also, consider reading [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Diziet Asahi Oct 02 '19 at 20:33

0 Answers0