Two-dimensional plots on Python [Part II]

Published on Author alexandrejaguarLeave a comment

Hey scientist! How do you do?
We’ll continue the tips about 2D plotsĀ on Python. Today we’ll work on the previous example, modifying the plot the way we want it. Let’s go!

Do you remember the last example? Here it is:

This code is nicely commented on the previous post. If you are confused, take a look there [1].

Also, do you remember the resulting plot? It follows:

Let’s suppose you don’t want the same plot always; we can change the color, increase the line width, change the like style… for example, instead of blue, how about a red line? For that, we can use plot() like this:

When we change the raw plot(t, y) for this line, the example code generates the following plot:

Yeah! Piece of cake šŸ˜‰

Following with the customizations, we can use linewidth to determine the line width. You can put any positive number here; Python understands it as the dot size. We have also linestyle, which controlsĀ the line style: '-' for a continuous line (the default one), '--' for a dashed line, '-.' for a dot-and-dash line, ':' for a dotted line, 'steps' for a “stair” line.

The pyplot tutorial [2] provides all plot properties that you can edit. Check it out!

We can also change the font size of X and Y axis, using the commands xlabel and ylabel. xlabel, ylabel and title have the parameters fontsize, color, fontweight, among many others.

How about try the code with some changes? Let’s make a green plot, dot-and-dash, line width of 3, bold axes labels, size 14. Whew! The code follows:

And the resulting plot is:

Awesome! Some more instructions and we have a custom plot.

Did you like this post? Please comment below! Share your ideas and tests, let’s try some stuff. Next week I’ll continue this 2D plots series!

Gigaregards and Happy New Year!

Did you like this post? Please comment and share with your friends!
Want to download Programming Science codes? Go to our GitHub!
I’m on Twitter: @alexdesiqueira! Follow me if you can!
Make a donation for Programming Science!

ShareEmail this to someoneShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on TumblrPin on Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *