Skip to content

Commit 6dcd4eb

Browse files
committed
2 parents 8eb5019 + 018d4c4 commit 6dcd4eb

File tree

7 files changed

+266
-1
lines changed

7 files changed

+266
-1
lines changed

chaoxi/BaseMap/Python_BaseMap1.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import matplotlib.pyplot as plt
2+
from mpl_toolkits.basemap import Basemap
3+
import numpy as np
4+
5+
# 画海岸线
6+
def drawcoast():
7+
8+
plt.figure(figsize=(12, 8))
9+
m = Basemap() # 创建一个地图
10+
m.drawcoastlines() # 画海岸线
11+
plt.show() # 显示图像
12+
13+
# 地球基本画法
14+
def draw_basic():
15+
map = Basemap(projection='ortho', lat_0=0, lon_0=0)
16+
map.drawmapboundary(fill_color='aqua')
17+
map.fillcontinents(color='gray',lake_color='aqua')
18+
map.drawcoastlines()
19+
plt.show()
20+
21+
# 画中国地图
22+
def draw_china():
23+
plt.figure(figsize=(10, 6))
24+
m = Basemap(llcrnrlon=77, llcrnrlat=14, urcrnrlon=140, urcrnrlat=51, projection='lcc', lat_1=33, lat_2=45,
25+
lon_0=100)
26+
m.drawcountries(linewidth=1.5)
27+
m.drawcoastlines()
28+
plt.show()
29+
30+
# 画地球人口分布图
31+
def drawearth():
32+
names = []
33+
pops = []
34+
lats = []
35+
lons = []
36+
countries = []
37+
file = open("data/main_city", encoding='utf-8').readlines()
38+
for line in file:
39+
info = line.split()
40+
names.append(info[0])
41+
pops.append(float(info[1]))
42+
lat = float(info[2][:-1])
43+
if info[2][-1] == 'S': lat = -lat
44+
lats.append(lat)
45+
lon = float(info[3][:-1])
46+
if info[3][-1] == 'W': lon = -lon + 360.0
47+
lons.append(lon)
48+
country = info[4]
49+
countries.append(country)
50+
# set up map projection with
51+
# use low resolution coastlines.
52+
map = Basemap(projection='ortho', lat_0=35, lon_0=120, resolution='l')
53+
# draw coastlines, country boundaries, fill continents.
54+
map.drawcoastlines(linewidth=0.25)
55+
map.drawcountries(linewidth=0.25)
56+
# draw the edge of the map projection region (the projection limb)
57+
map.drawmapboundary(fill_color='#689CD2')
58+
# draw lat/lon grid lines every 30 degrees.
59+
map.drawmeridians(np.arange(0, 360, 30))
60+
map.drawparallels(np.arange(-90, 90, 30))
61+
# Fill continent wit a different color
62+
map.fillcontinents(color='#BF9E30', lake_color='#689CD2', zorder=0)
63+
# compute native map projection coordinates of lat/lon grid.
64+
x, y = map(lons, lats)
65+
max_pop = max(pops)
66+
# Plot each city in a loop.
67+
# Set some parameters
68+
size_factor = 80.0
69+
y_offset = 15.0
70+
rotation = 30
71+
for i, j, k, name in zip(x, y, pops, names):
72+
size = size_factor * k / max_pop
73+
cs = map.scatter(i, j, s=size, marker='o', color='#FF5600')
74+
plt.text(i, j + y_offset, name, rotation=rotation, fontsize=10)
75+
76+
plt.title('earth')
77+
plt.show()
78+
79+
# 画带投影的地球图片
80+
def draw_earth1():
81+
import matplotlib.pyplot as plt
82+
from mpl_toolkits.basemap import Basemap
83+
plt.figure(figsize=(8, 8))
84+
# 正射投影,投影原点设在了上海周边
85+
m = Basemap(projection='ortho', resolution=None, lat_0=30, lon_0=120)
86+
# 图像原始分辨率是5400*2700,设置scale = 0.5以后分辨率为2700*1350,如此作图
87+
# 迅速不少也不那么占用内存了
88+
m.bluemarble(scale=0.5)
89+
plt.show()
90+
91+
if __name__ == '__main__':
92+
#drawcoast()
93+
drawearth()
94+
#draw_basic()
95+
#draw_china()
96+
#draw_earth1()

chaoxi/BaseMap/main_city

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Shanghai 23019148 31.23N 121.47E China
2+
Mumbai 12478447 18.96N 72.82E India
3+
Karachi 13050000 24.86N 67.01E Pakistan
4+
Delhi 16314838 28.67N 77.21E India
5+
Manila 11855975 14.62N 120.97E Philippines
6+
Seoul 23616000 37.56N 126.99E Korea(South)
7+
Jakarta 28019545 6.18S 106.83E Indonesia
8+
Tokyo 35682460 35.67N 139.77E Japan
9+
Peking 19612368 39.91N 116.39E China

chaoxi/Pandas1/pandas_example.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pandas as pd
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
def craw_bar():
6+
df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
7+
df2.plot.bar()
8+
plt.show()
9+
10+
def craw_line():
11+
ts = pd.Series(np.random.randn(1000), index=pd.date_range("1/1/2000", periods=1000))
12+
ts = ts.cumsum()
13+
ts.plot()
14+
plt.show()
15+
16+
def craw_line1():
17+
ts = pd.Series(np.random.randn(1000), index=pd.date_range("1/1/2000", periods=1000))
18+
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list("ABCD"))
19+
df = df.cumsum()
20+
df.plot()
21+
plt.show()
22+
23+
24+
def craw_bar():
25+
ts = pd.Series(np.random.randn(1000), index=pd.date_range("1/1/2000", periods=1000))
26+
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list("ABCD"))
27+
plt.figure()
28+
df.iloc[5].plot(kind="bar")
29+
plt.show()
30+
31+
def craw_bar1():
32+
df2 = pd.DataFrame(np.random.rand(10, 4), columns=["a", "b", "c", "d"])
33+
df2.plot.bar()
34+
plt.show()
35+
36+
def craw_bar2():
37+
df2 = pd.DataFrame(np.random.rand(10, 4), columns=["a", "b", "c", "d"])
38+
df2.plot.bar(stacked=True)
39+
plt.show()
40+
41+
def craw_bar3():
42+
df2 = pd.DataFrame(np.random.rand(10, 4), columns=["a", "b", "c", "d"])
43+
df2.plot.barh(stacked=True)
44+
plt.show()
45+
46+
if __name__ == '__main__':
47+
craw_bar3()

chaoxi/Pandas2/pandas_example1.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import pandas as pd
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
def draw_pie():
6+
7+
series = pd.Series(3 * np.random.rand(4), index=["1", "2", "3", "4"], name="series")
8+
series.plot.pie(figsize=(6, 6));
9+
plt.show()
10+
11+
12+
def draw_pie1():
13+
df = pd.DataFrame(
14+
3 * np.random.rand(4, 2), index=["a", "b", "c", "d"], columns=["x", "y"])
15+
df.plot.pie(subplots=True, figsize=(8, 4), legend=False)
16+
plt.show()
17+
18+
def draw_pie2():
19+
series = pd.Series(3 * np.random.rand(4), index=["1", "2", "3", "4"], name="series")
20+
series.plot.pie(
21+
labels=["A", "B", "C", "D"],
22+
colors=["r", "g", "b", "c"],
23+
autopct="%.2f",
24+
fontsize=20,
25+
figsize=(6, 6),)
26+
plt.show()
27+
28+
def draw_pie3():
29+
series = pd.Series([0.1] * 4, index=["a", "b", "c", "d"], name="series2")
30+
series.plot.pie(figsize=(6, 6))
31+
plt.show()
32+
33+
import pandas as pd
34+
import numpy as np
35+
import matplotlib.pyplot as plt
36+
from pandas.plotting import scatter_matrix
37+
def draw_pie4():
38+
39+
df = pd.DataFrame(np.random.randn(1000, 4), columns=["a", "b", "c", "d"])
40+
41+
scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal="kde")
42+
plt.show()
43+
44+
if __name__ == '__main__':
45+
draw_pie4()

chaoxi/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ Python技术 公众号文章代码库
77

88
![](http://favorites.ren/assets/images/python.jpg)
99

10-
## 实例代码
10+
## 实例代码
11+
12+
[神器 Pandas 绘图大全(上)!](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/Pandas2) 神器 Pandas 绘图大全(中)!
13+
14+
[神器 Pandas 绘图大全(上)!](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/Pandas1) 神器 Pandas 绘图大全(上)!
15+
16+
[神器-可视化分析之Basemap实战详解(二)](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/BaseMap) 神器-可视化分析之Basemap实战详解(二)
1117

1218
[用 Python 给小表弟画皮卡丘!](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/pkq) 用 Python 给小表弟画皮卡丘!
1319

moumoubaimifan/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Python技术 公众号文章代码库
1010

1111
## 实例代码
1212

13+
[又是入刑的一天!抓取 jk 小姐姐图片](https://github.com/JustDoPython/python-examples/tree/master/moumoubaimifan/jk)
14+
1315
[我不做韭菜!用 python 分析基金中的股票信息](https://github.com/JustDoPython/python-examples/tree/master/moumoubaimifan/stock.py)
1416

1517
[python 抓取阿里云盘资源](https://github.com/JustDoPython/python-examples/tree/master/moumoubaimifan/aliso)

moumoubaimifan/jk/jk.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import requests
2+
import time
3+
import json
4+
import re
5+
6+
header = {
7+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
8+
}
9+
10+
def get_list():
11+
12+
try:
13+
url = 'https://bcy.net/apiv3/common/circleFeed?circle_id=492&since='+str(int(time.time()))+'.000000&sort_type=2&grid_type=10'
14+
response = requests.get(url,headers= header)
15+
response.raise_for_status()
16+
#转码
17+
response.encoding = 'utf-8'
18+
return response.text
19+
except:
20+
print("Failed!")
21+
22+
def parse_list(data):
23+
item_ids = []
24+
json_data = json.loads(data)
25+
for item in json_data['data']['items']:
26+
item_ids.append(item['item_detail']['item_id'])
27+
return item_ids
28+
29+
def get_item(item_ids):
30+
intercepts = []
31+
for id in item_ids:
32+
url = 'https://bcy.net/item/detail/'+ str(id) + '?_source_page=hashtag'
33+
response = requests.get(url, headers = header)
34+
response.encoding = 'utf-8'
35+
text = response.text
36+
intercept = text[text.index('JSON.parse("') + len('JSON.parse("'): text.index('");')].replace(r'\"',r'"')
37+
intercepts.append(intercept)
38+
return intercepts
39+
40+
def download(intercepts):
41+
for i in intercepts:
42+
# json_data = json.loads(i)
43+
pattern = re.compile('"multi":\[{"path":"(.*?)","type"')
44+
pattern_item_id = re.compile('"post_data":{"item_id":"(.*?)","uid"')
45+
b = pattern.findall(i)
46+
item_id = pattern_item_id.findall(i)[0]
47+
index = 0
48+
for url in b:
49+
index = index + 1
50+
content = re.sub(r'(\\u[a-zA-Z0-9]{4})',lambda x:x.group(1).encode("utf-8").decode("unicode-escape"),url)
51+
response = requests.get(content.replace('\\',''))
52+
with open('D:\\bcy\\' + str(item_id) + str(index) + '.png', 'wb') as f:
53+
f.write(response.content)
54+
55+
if __name__ == '__main__':
56+
data = get_list()
57+
item_ids = parse_list(data)
58+
intercepts = get_item(item_ids)
59+
download(intercepts)
60+

0 commit comments

Comments
 (0)