Git Product home page Git Product logo

bird-visualization_warmup's Introduction

For today's warmup, we will practice our matplotlib visualization skills while visualizing bird sighting data gathered from the Cornell Ornithology eBird API.

Cornell Ornithology

import pickle
import matplotlib.pyplot as plt
with open('data/central_park_birds', 'rb') as read_file:
    central_park_birds = pickle.load(read_file)

Task 1: Most Common Bird Bar Chart

The dictionary loaded above contains recent counts of bird species sighted in Central Park.

Recent visitors to the park include this little dude:

Northern Saw-whet Owl

Your first task is to make a bar chart visualizing the counts of the top 10 most commonly sighted birds in the park. You should aspire to use the fig, ax = plt.subplots() syntax, but if you're not there yet, use the plt stateless syntax.

The first challenge is to sort the dictionary. Google how to do so.

# Your code here
sorted_birds = None
# If you are spending to much time on that, run this cell to return the sorted object.
with open('data/sorted_birds', 'rb') as read_file:
    sorted_birds = pickle.load(read_file)

Next, select the first 10 birds in the sorted_birds object. Then create two separate lists: one list containing the bird names, and one list containing the counts. These lists should preserve the relationship between name and count by aligned indices.

top_10_bird_names = None
top_10_bird_counts = None

Now, create a bar chart with these two lists. You may have some tick problems, which I'll let you sort out your own solution to. Don't forget plt.subplots()

Also, don't forget a title and axis labels

# Your code here

Task 2: Crow Distributions

Now we will broaden our territory, but focus on a single species: The American Crow.

American Crow

with open('data/crow_counts', 'rb') as read_file:
    cp_crows, loop_crows, seattle_crows = pickle.load(read_file)

The above cell loaded 3 lists of crow sighting counts near the central latitude/longitude of Central Park, Chicago's Loop, and Seattle.

One could say each element represents a murder.

The first part of the task is to make a histogram visualizing the distribution of number of crows per sighting.

So, firstly, you must create a new list that merges all 3 lists.

# Your code here
all_crows = None

Now, create a histogram that shows the distribution of crow counts.

 # Your code here

Your histogram should have looked pretty boring: 1 large spike near zero, with an x-axis range from 0 to around 10000.

Pray for the people of Seattle if that major outlier is not an input error.

Next, let's plot a boxplot to see what it tells us.

# Your code here

The boxplot should also look odd. Those little circles are the outliers. Recreate the boxplot, but this time remove the outliers via the showfliers argument.

By removing the fliers, we can see the components of the boxplot: the median at 3 crows, and the top and bottom edges of the box representing the interquartile ranges, and the whiskers, which are 1.5 times the IQR above the top of the box.

If you assign the boxplot axis to a variable (perhaps bp), you can then access information about the plot. We can get the value of the end of the whisker, i.e. the value whereafter matplotlib designates points as outliers, via the following code bp['whiskers'][1].get_ydata()

bp['whiskers'][1].get_ydata()
array([ 5., 11.])

Given the above output, reduce the original all_crows object to contain only non-outlier elements.

# your code here
Lastly, create a histogram without outliers.
# your code here

bird-visualization_warmup's People

Contributors

j-max avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.