3
$\begingroup$

Here I have a dataset with three values. I plot these three values in one graph using python. While I plot the graph first plot line is not coming properly. Because start point and end point combined with a line. So does anyone know how to remove this line? I'm stuck with this error. Please can you all help me to solve this error? Here is my code

data=pd.read_csv('data1.csv')
data = pd.DataFrame(['date', 'time','x1','x2','x3'])
x = pd.to_datetime(data['date'] + ' ' + data['time'], format='%d/%m/%Y %H:%M:%S')
y =data.iloc[:,2]
y1=data.iloc[:,3]
y2=data.iloc[:,4]
idx = ~np.isnan(y)
idx1=~np.isnan(y1)
idx2=~np.isnan(y2)
import matplotlib.dates as mdates
fig = plt.figure(figsize=(6,6))
ax=fig.add_subplot(111, label="1")
ax2=fig.add_subplot(111,label="2", frame_on=False)
ax3=fig.add_subplot(111,label="3", frame_on=False)
ax.plot(x[idx],y[idx], color="C0")
ax.set_xlabel("date1 label 1", color="C0")
ax.set_ylabel("y label 1", color="C0")
hours = mdates.HourLocator(interval =10)
h_fmt = mdates.DateFormatter('%H')
ax.xaxis.set_major_locator(hours)
ax.xaxis.set_major_formatter(h_fmt)
#ax.set_xlim([xmin,xmax])
#ax.set_ylim([ymin,ymax])
ax.tick_params(axis='x', colors="C0")
ax.tick_params(axis='y', colors="C0")
ax2.plot(x[idx1], y2[idx1],'g*')
ax2.xaxis.tick_top()
ax2.yaxis.tick_right()
ax2.set_xlabel('x label 2', color="C1") 
ax2.set_ylabel('y label 2', color="C1")       
ax2.xaxis.set_label_position('top') 
ax2.yaxis.set_label_position('right')
hours = mdates.HourLocator(interval =10)
h_fmt = mdates.DateFormatter('%H')
ax2.xaxis.set_major_locator(hours)
ax2.xaxis.set_major_formatter(h_fmt)
#ax2.set_xlim([xmin,xmax])
#ax2.set_y1lim([y1min,y1max])
ax2.tick_params(axis='x', colors="C1")
ax2.tick_params(axis='y1', colors="C1")
ax3.plot(x[idx2], y1[idx2],'k.')
hours = mdates.HourLocator(interval =10)
h_fmt = mdates.DateFormatter('%H')
ax3.xaxis.set_major_locator(hours)
ax3.xaxis.set_major_formatter(h_fmt)
#ax3.set_xlim([xmin,xmax])
#ax3.set_y3lim([y3min,y3max])
ax3.set_xticks([])
ax3.set_yticks([])
fig.autofmt_xdate(rotation=90)
plt.show()

Here I attached the my csv file link. https://docs.google.com/spreadsheets/d/1y6LKGIftb7F0ovF2dYsMwmvkR_diJBhBNC6sIiaagbI/edit?usp=sharing

my graph:

enter image description here

$\endgroup$
  • $\begingroup$ could you show your code reading the excel file and how you create your datasets or dataframe? $\endgroup$ – Frenchy Feb 25 '19 at 10:24
  • $\begingroup$ @Frenchy I changed the format. I upload my code. $\endgroup$ – user59020 Feb 25 '19 at 15:53
0
$\begingroup$

Matplotlib plots data in lists from left to right.

Hence, in the list x[idx] which is used in ax.plot(x[idx],y[idx], color="C0"), I assume that either the first element (according to x-axis) is in the back of the list, or the last element is at the beginning of the list.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Juric Sorry I didn't get what are you saying. $\endgroup$ – user59020 Feb 25 '19 at 15:55
0
$\begingroup$

From the uploaded .csv file, it appears that your data is repeated 3 times. Try removing the last two thirds of the file.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy