I am trying to plot a numpy array in such a way that all the points with the same y-axis value should be connected in the a straight line. But some how I am unable to achieve this.
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
# Declare numpy array with nans
x=np.array([np.nan,10005,10005,10006,10006,10006,10007,10007,10007, 10008,10007,10008,10008,10008, np.nan,10010,10010,10010, np.nan, np.nan, np.nan, np.nan])
# Plot the points
plt.plot(x, marker="o", linestyle='-')
# Display the plot in the window
plt.show()
This results in:
But I would like the plot to be:
Also, if there is a way to add some margin at the top and bottom of the plot to display the boundary points clearly.