"Actual Combat" The Secret of Nanjing Housing Prices-Community Prices "1"

img

Hello, I am Yuechuang.

In the last article, I shared with you " The Secret of "Actual" Nanjing Housing Prices-Preparation ", and then I will use three articles to share simple data visualization with you.

Nanjing is the capital of Jiangsu Province, a national historical and cultural city, an important national scientific research and education base and a comprehensive transportation hub. As the only mega-city in the Yangtze River Delta (Shanghai is positioned as a mega-city), Nanjing's housing prices are indeed not low. Judging from the current average city price, it has approached 29,000 yuan per square meter, which is a stable Jiangsu brother. What is the actual situation? Starting from this section, we will talk about data visualization while talking about housing prices in Nanjing.

This series of actual combat articles focuses on technical explanations, so the concept of commercial housing is not strictly limited. For some resettlement houses, housing reform houses, and welfare houses, as long as they can be listed and circulated, Xiaoyue does not make a distinction.

Xiaoqu_NJ_format.csv The file saved in the previous article, you can click the article in the previous chapter to operate it again

Overview of Nanjing Community

import pandas as pd
import numpy as np
Xiaoqu = pd.read_csv("Xiaoqu_NJ_format.csv", dtype=np.str)
Xiaoqu.shape
Out: (5082, 16)

According to statistics, there are 5,082 communities of various types in Nanjing. What about the district districts in each city? Here we introduce matplotlib's histogram method bar() .

The first thing that needs to be emphasized is that the matplotlib drawing process is very simple, and it mainly follows 3 basic steps:

(1) Draw and set the canvas;

(2) Selection of diagram type and setting of drawing data;

(3) Set other attributes of the graph, such as title, axis, etc.

Case 1: Draw the distribution map of the districts and counties in Nanjing-histogram

Because it is demonstrated in the jupyter notebook, the picture needs to be displayed in the notebook, so a magic command needs to be added:

%matplotlib inline	# 魔法命令,作用是把生成的图片嵌入到notebook中
import matplotlib.pyplot as plt
# 设置绘图的字体,特别是中文字体需要注意,避免出现乱码的情况
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# 基于统计命令,生成待绘图的数据
Series_bar = Xiaoqu["区县定位"].value_counts()
x_data = Series_bar.index.tolist()
y_data = Series_bar.values.tolist()
x_data
Out: ['鼓楼', '江宁', '秦淮', '玄武', '建邺', '浦口', '栖霞', '雨花台', '六合', '溧水', '高淳']
y_data
Out: [915, 849, 807, 460, 406, 395, 380, 314, 265, 194, 97]
# step 1:设置画布大小
plt.figure(figsize=(8, 6))

# step 2:基于bar函数的关键绘图语句(柱状图)
plt.bar(x_data, y_data, facecolor="r", label="小区数量", width=0.5, alpha=0.6)

# step 3:设置图的其他属性
plt.title("南京各区域小区数量", fontsize=15)	# 设置图标题,标题字号,建议标题字号通常大一些
plt.xticks(fontsize=12)	# 设置横轴字号
plt.yticks(fontsize=12)	# 设置纵轴字号
plt.legend()	# 设置显示图例

image description

At this point, one of the most common drawing processes is introduced. It should be noted that the key parameters of the bar() function are the most common parameters listed in the above script:

color: used to designate the color of the column, "r" means red, commonly "g" (green), "y" (yellow), "k" (black), "b" (blue), etc. More generally, you can pass in the hexadecimal color code, refer to the link: https://www.runoob.com/html/html-colorvalues.html

  • label: Used to specify the name of the legend;

  • width: used to specify the width of each column (0~1);

  • alpha: Transparency (0~1), usually in order to make the color softer, the value can be adjusted;

Guess you like

Origin blog.csdn.net/qq_33254766/article/details/108396830