Matplotlib plot is not displaying all xticks and yticks

  matplotlib, python-3.x

I am creating subplots in matplotlib but not all xticks and yticks are being displayed. I have tried everything from setting xlim and ylim, chainging figure size etc. The thing is this is a handson on hackerrnak and they are evaluating my output against their expected output. The 0.0 in xaxis and 1.0 on yaxis are simply not matching up. What am I doing wrong here.

Here is the code,

import matplotlib.pyplot as plt
import numpy as np

def test_generate_figure2():
    np.random.seed(1000)
    x = np.random.rand(10)
    y = np.random.rand(10)
    z = np.sqrt(x**2 + y**2)
    fig = plt.figure(figsize=(8,6))
    axes1 = plt.subplot(2, 2, 1, title="Scatter plot with Upper Triangle Markers")
    axes1.set_xticks([0.0, 0.4, 0.8, 1.2])
    axes1.set_yticks([-0.2, 0.2, 0.6, 1.0])
    axes1.set_ylim(-0.2,1.0) #Doing this still doesnot get the expected output
    axes1.set_xlim(0.0,1.2)
    print(axes1.get_yticks())
    axes1.scatter(x, y, marker="^", s=80, c=z)
    
    axes2 = plt.subplot(2, 2, 2, title="Scatter plot with Plus Markers")
    axes2.set_xticks([0.0, 0.4, 0.8, 1.2])
    axes2.set_yticks([-0.2, 0.2, 0.6, 1.0])
    axes2.scatter(x, y, marker="+", s=80, c=z)
    
    axes3 = plt.subplot(2, 2, 3, title="Scatter plot with Circle Markers")
    axes3.set_xticks([0.0, 0.4, 0.8, 1.2])
    axes3.set_yticks([-0.2, 0.2, 0.6, 1.0])
    axes3.scatter(x, y, marker="o", s=80, c=z)
    
    axes4 = plt.subplot(2, 2, 4, title="Scatter plot with Diamond Markers")
    axes4.set_xticks([0.0, 0.4, 0.8, 1.2])
    axes4.set_yticks([-0.2, 0.2, 0.6, 1.0])
    axes4.scatter(x, y, marker="d", s=80,c=z)
    
    plt.tight_layout()
    plt.show()
    
test_generate_figure2()

My Output,
My Output
Expected Output,
Expected Outpput

Source: Python-3x Questions

LEAVE A COMMENT