From the course: Python Data Visualization: Create Impactful Visuals, Animations, and Dashboards by Pearson

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

The plot function

The plot function

Now that we have loaded our data into our DataFrames, transformed it, and generated the final data that we actually need to plot, now we're ready to actually plot it using Pandas. Pandas provides us the plot function. This is a method on the DataFrame itself, where you can just call df.plot, and it will generate a plot for you. Naturally, you have to specify what column you want to use for the x-axis, what column you want to use for the y-axis. These are the two of the most important arguments you have to provide. By default, you will use the index as the x-axis if you provide only the y-axis. You can also specify what kind of plot you want to generate. You can have a line plot, a bar plot, horizontal bars with bar age, histogram plot with kind equals hist, a box plot with can equals box, pipe plot, or a scatter plot. So this will generate different types of plots based on the data that you have on that data frame. It sets a bunch of defaults for how the plot is generated, but more…

Contents