![]() Using pandas, different types of plots can be generated in a single line of code: ax = wine_df.plot(kind = 'scatter', x = 'Alcohol', y = 'OD280/OD315', c= 'Class', figsize=(12,8), colormap='jet')įor further customization, a similar plot can be made using just matplotlib: fig, ax = plt.subplots(figsize=(12,8))Īx.scatter(x = wine_df, y = wine_df, c = wine_df)Īx.set_ylabel('OD280/OD315', fontsize=15) ![]() In this case, we can plot wines based on their alcohol content (i.e., the x axis) and degree of dilution (i.e., an OD280/OD315 value shown along the y axis) in order to place them in a Class between 0 to 2. Plotting is an extremely useful tool in gaining an initial understanding of the data. When dealing with data for the first time, an exploratory analysis is typically the first thing that is done. The second is the el nino dataset, which contains spatiotemporal data from a series of buoys in the Pacific Ocean taken during the El Nino cycle of 1982-1983. Each observation consists of 13 features that are the result of a chemical analysis. The first is the wine dataset, which provides 178 clean observations of wine grown in the same region in Italy. ![]() I pulled two different datasets from the UCI Machine Learning Repository. Header = None,na_values = '.', sep = '\s+', names = nino_names)) Wine_df.Class = wine_df.Class.astype('object') Wine_df = pd.DataFrame(pd.read_csv('', names = wine_names)) Wine_names = ['Class', 'Alcohol', 'MalicAcid', 'Ash', 'Alc.Ash', 'Magnesium', 'TotalPhenols', \ To demonstrate the versatility of matplotlib, let’s import a few different datasets: import pandas as pd You can install Basemap by following the instructions here. I’ll be using pandas in addition to Basemap, which doesn’t come with the standard installation of matplotlib. Matplotlib is also integrated into the pandas package, which provides a quick and efficient tool for exploratory analysis. Seaborn and Holoviews provide higher level interfaces, which results in a more intuitive experience. ![]() There are many third-party packages that extend the functionality of matplotlib such as Basemap and Cartopy, which are ideal for plotting geospatial and map-like data. This allows for complete customization and fine control over the aesthetics of each plot, albeit with a lot of additional lines of code. It is similar to plotting in MATLAB, allowing users full control over fonts, line styles, colors, and axes properties. Matplotlib is quite possibly the simplest way to plot data in Python. Matplotlib vs Plotly: Plotting Data with Matplotlib If you’re on a different OS, you can automatically build your own custom Python runtime with just the packages you’ll need for this project by creating a free ActiveState Platform account. If you don’t have a recent version of Python, I recommend doing one of the following: Download and install the pre-built “Data Plotting” runtime environment for Windows 10 or CentOS 7, or If you want to follow along with this tutorial, you’ll need to have Python installed with the required packages. In this article, I will compare and demonstrate two common visualization tools used in Python: matplotlib and plotly. When it comes down to choosing how to visualize one’s data, the best tool for the job depends on the type of data, the purpose of the visualization, and the aesthetics which you hope to achieve. Whether it’s an initial exploratory analysis or a presentation to non-technical colleagues, proper visualization lies at the heart of data science. Data visualization provides a powerful tool to explore, understand, and communicate the valuable insights and relationships that may be hidden within data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |