A case of drawing ridge map with joypy


1、 Concept introduction

Ridge line plot is used to show the distribution of several data in the same dimension. Each layer of ridge line (peak) is a histogram or density map, which is stacked layer by layer to form the final ridge line map.

·Ridge graph is generally used to compare the numerical distribution of continuous variables of multiple categories (> 5). Therefore, if the value range of a data is too small or the distribution is average, the fluctuation is not easy to detect and affects the visual beauty of the graph.

Graphic example:

A case of drawing ridge map with joypy

What we need to know is that the abscissa of the ridge graph is the numerical distribution interval, which is more like the y-axis we often use; The ordinate is the class mark of each numerical sequence; The crest of the ridge line represents that the corresponding value distribution is concentrated and the frequency is high.

2、 Data display

In this case, we hope to show the distribution of daily maximum temperature and minimum temperature of eight randomly selected cities in the past year through ridge map.

Data fromGuangzhou November weather | Guangzhou November temperature | Guangzhou November 2021 historical weather – Global Weather Network

With the help of crawler tool, we simply collected the daily data from December 2020 to November 2021, and obtained the following excel set

A case of drawing ridge map with joypy

The data of each excel table is presented as follows:

A case of drawing ridge map with joypy

For the same version of data, mosaic maps are also drawn for climate types~

Interested friends can pokehttps://blog.csdn.net/qq_45400322/article/details/122522620

3、 Data read in

import pandas as pd
city8_fullname_py = ['beijing','chongqing','wuhan','shenzhen','nanjing','guangzhou','chengdu','shanghai']
city8_ Fullname = ['Beijing', 'Chongqing', 'Wuhan', 'Shenzhen', 'Nanjing', 'Guangzhou', 'Chengdu', 'Shanghai']

weather_dic = {}
for i in range(len(city8_fullname)):
    df = pd. Dataframe (PD. Read_excel ('. / 2021 urban temperature data / 2021 temperature data' + city8_fullname_py [i] + '. XLS'))
    weather_ DIC [city8_fullname [i]] = DF [['date', 'maximum temperature', 'minimum temperature', 'climate type']]
    weather_ DIC [city8_fullname [i]] ['city'] = PD Series([city8_fullname[i]]*df.shape[0])
weather = weather_dic[city8_fullname[0]]
for i in range(1,8):
    weather = pd.concat([weather,weather_dic[city8_fullname[i]]],ignore_index="true")

The obtained data is stored in weather with the following structure:

A case of drawing ridge map with joypy

4、 Image rendering

We need joypy bags here

import joypy
import matplotlib.pyplot as plt

plt.figure(dpi= 90)
fig, axes = joypy. Joyplot (weather, column = ['highest temperature', 'lowest temperature'], by = "city", figsize = (13,9),
                          fill=True, legend=True,alpha=.8,
plt. Title ('temperature distribution of eight cities in the past year ', fontsize = 25, vertical alignment ='bottom')
plt. Savefig (R '. / mapping results / weather - temperature distribution in the past year - ridge diagram. PNG')

By —- in the drawing, that is, our ordinate and data category need to be specified.

Fill —- whether color filling is required

Alpha —- in the visual images with image coverage such as area map and ridge map, we recommend adjusting the transparency to display the outline of the covered part at the same time. Of course, if there are area differences in the data itself, the category with as small an area as possible will be preceded.

The results are as follows:

A case of drawing ridge map with joypy

If you have any questions, please communicate in the comment area~

Recommended Today

2021-11-09 volcano map based on RNA SEQ table (second time)

setwd(“C:\\Users\\Administrator.DESKTOP-4UQ3Q0K\\Desktop”) library(“readxl”) data <- read_excel(“RNA-seq.xlsx”) library(dplyr) library(ggplot2) library(ggrepel) data #Convert to tibble for subsequent use and remove unnecessary columns; Data < – Data [C (- 10, – 11, – 14, – 15, – 16, – 19, – 20, – 21, – 22)] # don’t try #data <- as_tibble(data[c(-10,-11,-14,-15,-16,-19,-20,-21,-22)]) data$padj<-as.numeric(as.matrix(data$padj)) #Take logarithm of Q value; data$log10FDR […]