Here, facecolor would set the color of the figure as a whole.įig.set_size_inches(10, 5) creates a 1000 × 500 px figure. All the code snippets below should be placed inside one cell in your Jupyter Notebook.įig, ax = plt.subplots(facecolor='#f0eeee')Īx.plot('date', 'Immigration', data=df, color='#5d35f2', linewidth=3)įig, ax = plt.subplots(facecolor='#f0eeee') - this would create a figure with one subplot. We’ll create a Matplotlib line chart with annotations in 6 steps. We’ll need the following variables for plotting: We’ll need this to change the format from “year-month-day” to “year-month” on our graph. We also must tell Matplotlib that the dates in our data set are indeed dates:ĭf = pd.to_datetime(df, format='%Y/%m/%d') Our first annotation would be for values in rows #66 (), the second #78 (), and the third #150 (). Maximums = df.sort_values(by='Immigration', ascending=False).head() Let’s also find maximum values - we’ll need to know them to create annotations: We delete all columns except “date” and “immigration”.ĭf = df.drop(labels=,axis='columns') On the second line in your Jupyter notebook, type this code to read the file. You can download the file on GitHub ( imm_trends.csv). Let’s create a Matplotlib line chart with annotations showing Google trends related to immigration. You’ll need the last line ( %matplotlib notebook) to display plots in input cells. In the first line of the notebook, import all the necessary libraries: This will automatically open the Jupyter home page at Click on the “New” button in the top right corner, select the Python version installed on your machine, and a notebook will open in a new browser window. “matplotlib-line-chart”) and open Jupyter Notebook by typing this command in your terminal (don’t forget to change the path):Ĭd C:\Users\Shark\Documents\code\matplotlib-line-chart Pip install numpy scipy matplotlib ipython jupyter pandas sympy nose seabornĬreate a folder that will contain your notebook (e.g. To get other tools, you’ll need to install recommended Scientific Python Distributions. You can download the latest version of Python for Windows on the official website. Seaborn: a plotting library (we’ll only use part of its functionally to add a grid to the plot and get rid of Matplotlib borders). Pandas: a library to create data frames from data sets and prepare data for plotting.Jupyter Notebook: an online editor for data visualization.Pip: package management system (it comes with Python).To create a line chart with annotations, we’ll need the following:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |