Get startedGet started for free

Plotting your Twitter data

Now that you have the number of tweets that each candidate was mentioned in, you can plot a bar chart of this data. You'll use the statistical data visualization library seaborn, which you may not have seen before, but we'll guide you through. You'll first import seaborn as sns. You'll then construct a barplot of the data using sns.barplot, passing it two arguments:

  1. a list of labels and
  2. a list containing the variables you wish to plot (clinton, trump and so on.)

Hopefully, you'll see that Trump was unreasonably represented! We have already run the previous exercise solutions in your environment.

This exercise is part of the course

Intermediate Importing Data in Python

View Course

Exercise instructions

  • Import both matplotlib.pyplot and seaborn using the aliases plt and sns, respectively.
  • Complete the arguments of sns.barplot:
    • The first argument should be the list of labels to appear on the x-axis (created in the previous step).
    • The second argument should be a list of the variables you wish to plot, as produced in the previous exercise (i.e. a list containing clinton, trump, etc).

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import packages



# Set seaborn style
sns.set(color_codes=True)

# Create a list of labels:cd
cd = ['clinton', 'trump', 'sanders', 'cruz']

# Plot the bar chart
ax = sns.barplot(____, ____)
ax.set(ylabel="count")
plt.show()
Edit and Run Code