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 histogram of this data and this is what you'll do in this final exercise.

Hopefully, you'll see that Trump was unreasonably represented! In the pre-exercise code, we have run the previous exercise solutions.

This exercise is part of the course

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 labels to appear on the x-axis; the second argument should be the list of the numbers to appear on the y-axis, as produced in the previous exercise.

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)

# Plot histogram
cd = ['clinton', 'trump', 'sanders', 'cruz']
ax = sns.barplot(____, ____)
ax.set(ylabel="count")
plt.show()
Edit and Run Code