GithubHelp home page GithubHelp logo

dlab-berkeley / python-data-visualization-legacy Goto Github PK

View Code? Open in Web Editor NEW
56.0 9.0 43.0 5.76 MB

D-Lab's 3 hour introduction to data visualization with Python. Learn how to create histograms, bar plots, box plots, scatter plots, compound figures, and more, using matplotlib and seaborn.

License: Other

Jupyter Notebook 100.00%
python data-visualization data-science matplotlib seaborn pandas

python-data-visualization-legacy's Introduction

D-Lab's Python Data Visualization Workshop

This repository contains the materials for D-Lab's Python Data Visualization workshop. Prior experience with Python Fundamentals is assumed.

Workshop Goals

In this workshop, we provide an introduction to data visualization with Python. First, we'll cover some basics of visualization theory. Then, we'll explore how to plot data in Python using the matplotlib and seaborn packages. We aim to cover the following types of plots:

  • line plots
  • bar plots
  • scatter plots
  • boxplot
  • heat maps

We'll also learn how to customize and style plots. Throughout the workshop, we'll discuss the plot types best suited for particular kinds of data.

Basic familiarity with Python is assumed. If you are not familiar with the material in Python Fundamentals, we recommend attending that workshop first.

Installation Instructions

Anaconda is a useful package management software that allows you to run Python and Jupyter notebooks very easily. Installing Anaconda is the easiest way to make sure you have all the necessary software to run the materials for this workshop. Complete the following steps:

  1. Download and install Anaconda (Python 3.8 distribution). Click "Download" and then click 64-bit "Graphical Installer" for your current operating system.

  2. Download the Python-Data-Visualization workshop materials:

  • Click the green "Code" button in the top right of the repository information.
  • Click "Download Zip".
  • Extract this file to a folder on your computer where you can easily access it (we recommend Desktop).
  1. Optional: if you're familiar with git, you can instead clone this repository by opening a terminal and entering git clone [email protected]:dlab-berkeley/Python-Data-Visualization.git.

Run the code

Now that you have all the required software and materials, you need to run the code:

  1. Open the Anaconda Navigator application. You should see the green snake logo appear on your screen. Note that this can take a few minutes to load up the first time.

  2. Click the "Launch" button under "Jupyter Notebooks" and navigate through your file system to the Python-Data-Visualization folder you downloaded above.

  3. Open the lessons folder, and click Python-Data-Visualization.ipynb to begin.

  4. Press Shift + Enter (or Ctrl + Enter) to run a cell.

  5. By default, the necessary packages for this workshop should already be installed. You can install them within the Jupyter notebook by running the following line in its own cell:

!pip install -r requirements.txt

Note that all of the above steps can be run from the terminal, if you're familiar with how to interact with Anaconda in that fashion. However, using Anaconda Navigator is the easiest way to get started if this is your first time working with Anaconda.

Is Python not working on your laptop?

If you do not have Anaconda installed and the materials loaded on your workshop by the time it starts, we strongly recommend using the UC Berkeley Datahub to run the materials for these lessons. You can access the DataHub by clicking this button:

Datahub

The DataHub downloads this repository, along with any necessary packages, and allows you to run the materials in a Jupyter notebook that is stored on UC Berkeley's servers. No installation is necessary from your end - you only need an internet browser and a CalNet ID to log in. By using the DataHub, you can save your work and come back to it at any time. When you want to return to your saved work, just go straight to DataHub, sign in, and you click on the Python-Data-Visualization folder.

If you don't have a Berkeley CalNet ID, you can still run these lessons in the cloud, by clicking this button:

Binder

By using this button, however, you cannot save your work.

Additional Resources

Check out the following resources to learn more about data visualization:

About the UC Berkeley D-Lab

D-Lab works with Berkeley faculty, research staff, and students to advance data-intensive social science and humanities research. Our goal at D-Lab is to provide practical training, staff support, resources, and space to enable you to use R for your own research applications. Our services cater to all skill levels and no programming, statistical, or computer science backgrounds are necessary. We offer these services in the form of workshops, one-to-one consulting, and working groups that cover a variety of research topics, digital tools, and programming languages.

Visit the D-Lab homepage to learn more about us. You can view our calendar for upcoming events, learn about how to utilize our consulting and data services, and check out upcoming workshops.

Other D-Lab Python Workshops

Here are other Python workshops offered by the D-Lab:

Basic competency

Intermediate/advanced competency

python-data-visualization-legacy's People

Contributors

erthward avatar henchc avatar juanshishido avatar ktakimoto avatar pssachdeva avatar ruiz-michael avatar samyag1 avatar stemlock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-data-visualization-legacy's Issues

Title, xlabel, ylabel commands in the pandas hist function

Pratik suggested a great edit/addition for the title, xlabel, ylabel commands in the pandas hist function under the 'Pandas methods to make plots' section:

gm_latest.hist(column='gdpPercap', bins=3)
plt.title('Distribution of Global Per-Capita GDP in 2007')
plt.xlabel('Per-Capita GDP (Millions of USD)')
plt.ylabel('# of Countries')

Simplifying plot code in Bar Plot section

Currently, we are creating a lot of new variables in order to create a simple bar plot. Some of which are not even used, such as the x variable for ticks.

Instead, we could simplify the plot calls by using the country_counts dataframe columns directly.

Matplotlib plot call
plt.bar(country_counts['continent'], country_counts['n_countries']);

Pandas plot call
country_counts.plot(kind='bar', x='continent', y='n_countries', legend=False);

PyViz Workshop Notes 11-16-2021

7 participants at start of workshop. Feedback link wasn't working, so checked in with front desk/Aaron/Sev for help. Total of 9 participants at 1:45 pm. 8 as of 2:50 pm. Everything going well in workshop. 9 as of 3:39 pm.

  • Typo in this line here just above scatterplot section: "Does Spain or Portugal have a higher life expectantcy across all the years? How does this relate to per-capita GDP? How might we look for a relationship? - expectancy is spelled wrong.
  • Typo in this line here: "That looks much better. We can now see there is somehwhat of a linear relationship between the log of GDP and life expectancy. Interesting!" -somewhat is spelled wrong. It's just above the section on Transparency.
  • Also, the section head for the Transformations section needs correction - it reads: "Transormations".
  • In the section on Color - typo = "plt.ylabel('Life Expectency (Years)');" s/b "Expectancy"? @pssachdeva @bypdlab -add anything I might have missed

Line Plot Challenge

The challenge for the Line Plot section gives the same plot as the example that we use above, so we might want to try something different.

To get started, Pratik suggested we show more customizations (e.g., font size, etc.):

plt.figure(figsize=(10,5))
plt.plot(spain['year'], spain['lifeExp'], label='Spain')
plt.plot(portugal['year'], portugal['lifeExp'], label='Portugal')
plt.title('Life Expectantcy of Portugal & Spain', fontsize=18)
plt.xlabel('Time (Years)', fontsize=15)
plt.ylabel('Life Expectantcy (Years)', fontsize=15)
plt.legend(prop={'size': 13});

Reduce Quotes

Choose the most important key quotes and principles of theory in the first section, and lighten the theory to focus on examples and application.

Solution errors

Solution notebook, "Pandas approach", two cells return errors.

Incorporate Pie Chart vs Bar Chart visualization

Instead of looking at area/bars in an isolated case in the comparisons in the theory section, consider using a real-world example comparing area/length by looking at a pie chart vs bar chart comparison.

Incorporate plot.ly

Another important package for modern data visualization with Python is plot.ly. Consider including at least an example or reference in a 'Next Steps' section, or a larger section introducing the package.

Typos for 'expectancy' in challenge questions for histograms section and scatter plots section

There are a few typos across the notebook for 'expectancy'.

Fix the challenge questions in the histogram section to:

  1. Create a histogram of life expectancy in the year 2007 across all 142 countries in the gapminder dataset. Play with the bins= parameter to find the most informative bin number.

  2. What can you say about the distribution of life expectancy values in 2007?

Also fix the text in the plots of the scatter plot section.

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.