![]() To start we include the following libraries:ĭef convert_GeoPandas_to_Bokeh_format ( gdf ): """ Function to convert a GeoPandas GeoDataFrame to a Bokeh ColumnDataSource object. It also has built-in plotting mechanisms that use the Matplotlib library. ![]() GeoPandas extends the ease of working with the Pandas library for data analysis to geospatial analysis. The source code for this blog post can be found here. We first cover how to work with GeoPandas and then dive into plotting with Bokeh. Therefore we will also make use of the GeoPandas library which extends the power of Pandas to geospatial data analysis. We will be using geospatial data with the end goal of making an interactive plot of the Chicago "L" stations. This is important because Matplotlib and Seaborn will often fail if the datasets one is working with becomes too large. Bokeh is a Python library that generates interactive visualizations with ease and also can handle very large or streaming datasets. The purpose of this blog post is to go over some of the basics of plotting with Bokeh. ![]() (from official website).A Quick Intro To Interactive Visualizations With Bokeh ¶ Contents ¶ If one positional argument is passed in to the ColumnDataSource initializer, it will be taken as data. The ColumnDataSource takes a data parameter which is a dictionary, with string column names as keys and lists (or arrays) of data values as values. But the core of most Bokeh plots is ColumnDataSource.Īt the most basic level, a ColumnDataSource is simply a mapping between column names and lists of data. Bokeh accepts a lot of different types of data as the source for graphs and visuals: providing data directly using lists of values, pandas dataframes and series, numpy arrays and so on. Next, we will prepare a data source for our application. regions_list = final_df.region.unique().tolist()Ĭolor_mapper = CategoricalColorMapper(factors=regions_list, palette=Spectral6) Then we use CategoricalColorMapper to assign different color for each region. We select unique regions and convert them to a list. First, we create a color mapper for different regions of the world, so every country will have different color depends on the region it is situated in. We will start with a preparations of different details for our interactive visualization app. from bokeh.io import curdocįrom bokeh.models import HoverTool, ColumnDataSource, CategoricalColorMapper, Slider Upd_new_df = upd_new_df.astype( 'int64')ĭf_gdp = gapminder]ĭf_gdp.columns = įinal_df = pd.merge(upd_new_df, df_gdp, on=, how= 'left')īy the way, CO2 emissions and GDP correlate, and quite significantly - 0.78 np.corrcoef(np_co2, np_gdp)Īnd now let’s get to the visualization part. New_df = pd.melt(data_with_regions, id_vars=)Ĭolumns = Gapminder = pd.read_csv( 'data/gapminder_tidy.csv')ĭf = gapminder].drop_duplicates()ĭata_with_regions = pd.merge(data, df, left_on= 'country', right_on= 'Country', how= 'inner')ĭata_with_regions = data_with_regions.drop( 'Country', axis= 'columns') import pandas as pdĭata = pd.read_csv( 'data/co2_emissions_tonnes_per_person.csv') As article doesn’t focus on these steps I will just insert the code below with all the transformations I have made. Then we perform some EDA (exploratory data analysis) to understand what we are dealing with and after that cleaning and transforming data into format necessary for analysis. How do we start to analyze the data? Correct, by importing necessary packages and by importing data itself (very important :D). ![]() You can also download these files from here. So I took two files: one with CO2 emissions from and another from DataCamp course (because that file was already preprocessed □ yeeeeees, I am a lazy bastard □ ). Decided to visualize the changes in CO2 emissions in time and in correlation to GDP (and check if that correlation even exists, because you never know :|). So I created some kind of case study for myself. Bokeh can help anyone who would like to quickly and easily create interactive plots, dashboards, and data applications.” I think it’s pretty clear, but it would be much better to see it in action, wouldn’t it?īefore starting, make sure you have Bokeh installed in your environment, if you don’t have it, follow the installation instructions from here. Its goal is to provide elegant, concise construction of versatile graphics, and to extend this capability with high-performance interactivity over very large or streaming datasets. Recently I came over this library, learned a little about it, tried it, of course, and decided to share my thoughts.įrom official website: “Bokeh is an interactive visualization library that targets modern web browsers for presentation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |