Need Help : Finding the Best Markets to Advertise In

Screen Link:
https://app.dataquest.io/m/310/guided-project%3A-finding-the-best-markets-to-advertise-in/2/understanding-the-data

My Code is attached:

Finding the best markets to advertise.ipynb (230.1 KB)

What I expected to happen:
xticks in last bar graph should be in range (0,400).

What actually happened:

The last bar graph has two set of xticks. (0,400) and (0,1)

Click here to view the jupyter notebook file in a new tab

1 Like

Hi @ArchanaSoman

The code leads to 3 different plots due to axes, ax1 and ax2 forming separate plots.
Since fig, axes span the entire (15,12) grid, and then ax1 and ax2 come in they overlap on the entire axes plot.

My words won’t make sense so let’s see it practically. Add the code plt.show() at 3 different spots in your last code cell (I am giving the last code line from your code below which you need to add plt.show()):

  1. fig,axes =plt.subplots(figsize=(15,12))
    plt.show()
    
  2. ax1.set_xlabel("Amount spent per month",fontsize=15)
    plt.show()
    
  3. ax2.set_xlabel("Amount spent per month",fontsize=15)
    plt.show()
    

If you did it right you should see 3 different grids/plots areas, 1st very big with tick marks in floats, rest 2 plots will be as you designed via code.

Now the question is why is this happening. Because you haven’t assigned ax1 and ax2 as subplots of the parent plot figure (fig, axes).

There are several ways to do this. I have attached these following posts for reference and experiment. You will find more on the DQ comm.

Please do let us know in case you still have doubts or would like to a better solution.

1 Like