Python Matplotlib Drawing Multiple Curves

This is our second tutorial on Python Matplotlib, in this tutorial we are going to learn about Matplotlib Drawing Multiple Curves, so in the first tutorial we had a simple introduction to Matplotlib, also we have learned how you can install Matplotlib and we have created a simple example.

 

 

 

Matplotlib Tutorials For Beginners

1: Matplotlib Introduction & Installation 

 

 

 

So now this is the complete code for Python Matplotlib Drawing Multiple Curves

 

 

After runing of this code you will see that The two curves show up with a different color automatically picked up by matplotlib.  We use one function call plt.plot() for one curve; thus, we have to call plt.plot()  here twice. However, we still have to call plt.show() only once. The functions calls plt. plot(X, Ya) and plt.plot(X, Yb) can be seen as declarations of intentions. We want  to link those two sets of points with a distinct curve for each. matplotlib will simply keep note of this intention but will not plot anything yet. The plt.show() curve, however, will signal that we want to plot what we have described so far.

 

 

 

If you run the code this will be the result

Python Matplotlib Drawing Multiple Curves
Python Matplotlib Drawing Multiple Curves

 

 

 

 

 

So now let’s plot a curve from a file data. i have created a txt file in my working directory at name of data.txt, but you can name it what ever you want. and this is the simple data for our file.

 

 

 

 

OK this is the code for plotting of the data from a file.

 

 

So in the above code first we have imported our matplotlib library, after that we have created two empty lists, and than we have used for loop for opening of our txt file and appending that data to the two lists. at the end we have plotted the data.

 

 

 

 

After run this will be the result

Python Matplotlib Curve From File
Python Matplotlib Curve From File

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×