<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          魔都上海4日旅游攻略?Python動態(tài)圖告訴你!

          共 21281字,需瀏覽 43分鐘

           ·

          2021-08-30 08:49

          點擊上方“Python爬蟲與數(shù)據(jù)挖掘”,進行關(guān)注

          回復(fù)“書籍”即可獲贈Python從入門到進階共10本電子書

          博學(xué)而約取,厚積而薄發(fā)。

          開場段子 

          【野人獻(xiàn)曝】戰(zhàn)國時期,宋國有一個沒有見過世面的農(nóng)夫,由于家貧,終日穿一件粗麻衣,勉強過冬。第二年春天,天氣晴朗,他就脫光衣服在太陽下曝曬,覺得十分舒服。由于沒有見過漂亮的皮衣和高大的房子,就對妻子說將把這取暖的辦法進獻(xiàn)給國王。


          【成語釋義】比喻貢獻(xiàn)的不是什么珍貴的東西,常用于向人建議時候的客套話。


          魔都魔在哪里


          人們通常戲稱上海為魔都。那么上海魔在哪里呢?這里的魔主要有兩層含義。第一是魔力,第二是魔幻。


          先說魔力。上海是我國的金融中心,是我國經(jīng)濟總量第一的城市,是我國人均收入最高的城市,是我國進出口貿(mào)易第一的城市,也是我國最開放的城市之一。拼多多、B站、攜程、餓了么等知名互聯(lián)網(wǎng)公司的總部都在上海,騰訊、阿里、美團、頭條等在上海都有辦公部門。加之上海相比北京寬松的戶籍政策,每年吸引著無數(shù)打工人來上海追尋夢想。浪奔,浪流,萬里滔滔江水永不休。


          再說魔幻。上海是一座奇跡之城,從1843年作為通商口岸開放到如今不過170余年,上海從一個名不見經(jīng)傳的小村落一躍成為中國第一亞洲第二大城市,發(fā)展速度可謂奇跡。上海也是一座混沌之城,這里有見證800年暮鼓晨鐘的靜安寺,近600年歷史的城隍廟,歷經(jīng)450余年風(fēng)雨的豫園,也有外灘的“萬國建筑群”,“十里洋場”盛況空前,東方明珠奪目璀璨,亞洲第一高樓高達(dá)632米的上海中心大廈。可謂亦中亦西,亦今亦古


          上海旅游攻略


          上海知名度最高的旅游景點,應(yīng)該是上海外灘,東方明珠電視塔,以及迪士尼樂園。


          此外,豫園、南京路、人民廣場、靜安寺、新天地、陸家嘴、崇明島、朱家角、滴水湖、淀山湖、楓涇古鎮(zhèn) 等景點也是值得一去的好地方。


          這么多的景點?該如何規(guī)劃呢?下面這份上海4日旅游攻略,或許可以幫助到你。


          先上數(shù)據(jù)


          Day1 上海城隍廟旅游區(qū)(2小時) → 豫園(1小時) → 南京路步行街(3小時) → 外灘(1小時) 


          Day2 中華藝術(shù)宮(4小時) → 田子坊(2小時) → 上海新天地(2小時) 


          Day3 上海迪士尼度假區(qū)(1天) 


          Day4 上海杜莎夫人蠟像館(3小時) → 陸家嘴(2小時) → 東方明珠廣播電視塔(2小時)


          再上視頻



          最后上代碼


          import numpy as np 
          import pandas as pd 
          import geopandas as gpd 
          import shapely 
          from shapely import geometry as geo 
          from shapely import wkt 
          import geopandas as gpd 
          import matplotlib.pyplot as plt 
          import matplotlib.animation as  animation 
          import contextily as ctx

          import imageio
          import os 
          from PIL import Image

          plt.rcParams['font.family'] = 'sans-serif'
          plt.rcParams['font.sans-serif'] = ['SimHei']
          plt.rcParams['axes.unicode_minus'] = False
          plt.rcParams['animation.writer'] = 'html'
          plt.rcParams['animation.embed_limit'] = 100

          def rgba_to_rgb(img_rgba):
              img_rgb = Image.new("RGB", img_rgba.size, (255255255))
              img_rgb.paste(img_rgba, mask=img_rgba.split()[3]) 
              return img_rgb 

          def html_to_gif(html_file, gif_file, duration=0.5):
              path = html_file.replace(".html","_frames")
              images = [os.path.join(path,x) for x in sorted(os.listdir(path))]
              frames = [imageio.imread(x) for x in images]
              if frames[0].shape[-1]==4:
                  frames = [np.array(rgba_to_rgb(Image.fromarray(x))) for x in frames]
              imageio.mimsave(gif_file, frames, 'gif', duration=duration)
              return gif_file

          cmap = [
          '#2E91E5',
          '#1CA71C',
          '#DA16FF',
          '#B68100',
          '#EB663B',
          '#00A08B',
          '#FC0080',
          '#6C7C32',
          '#862A16',
          '#620042',
          '#DA60CA',
          '#0D2A63']*100


          def trace_map_dance(df,title = "上海經(jīng)典4日旅行路線",
                               filename = None,
                               figsize = (8,6),dpi = 144,
                               duration = 0.5,
                               anotate_points = ["外灘","上海迪士尼度假區(qū)","陸家嘴"])
          :


              fig, ax =plt.subplots(figsize=figsize,dpi=dpi)

              def plot_frame(i):

                      ax.clear()
                      ax.axis("off")
                      
                      k = i//3+1
                      m = i%3

                      dfdata = df.iloc[:k,:].copy()
                      dftmp = df.iloc[:k-1,:].copy()
                      text = dfdata["day"].tolist()[-1]
                      
                      #============================================================
                      #繪制背景
                      #============================================================
                      
                      #設(shè)置繪圖范圍
                      bounds = dfcity.total_bounds # k==1   
                      if 1<k<len(df)+1:
                          bounds = dfplace.query("day=='{}'".format(text)).total_bounds
                      if k>=len(df)+1:
                          bounds = dfplace.total_bounds
                          
                      (xmin,ymin,xmax,ymax) = bounds
                      cx = (xmin+xmax)/2.0
                      cy = (ymin+ymax)/2.0
                      dx = max(xmax-xmin,100)
                      dy = max(ymax-ymin,100)

                      if dx/dy<8/6.0:
                          dx = dy*8/6.0
                      else:
                          dy = dx*6.0/8
                      bounds = np.array([min(cx-8000,cx-dx/2.0),min(cy-6000,cy-dy/2.0),
                         max(cx+8000,cx+dx/2.0),max(cy+6000,cy+dy/2.0)])
                          
                      ax.set_xlim(bounds[0]-(bounds[2]-bounds[0])/3, bounds[2]+(bounds[2]-bounds[0])/3)    
                      ax.set_ylim(bounds[1]-(bounds[3]-bounds[1])/3, bounds[3]+(bounds[3]-bounds[1])/3)
                          
                      gaode = 'http://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7'
                      openstreet = "https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png"
                      ctx.add_basemap(ax,source=gaode,alpha=0.5)
                      
                      #============================================================
                      #繪制散點
                      #============================================================

                      # 繪制散點圖像
                      if len(dftmp)>0:
                          ax.scatter(dftmp["x"],dftmp["y"],s = 100*dftmp["z"]/df["z"].mean(),
                                 c = (cmap*100)[0:len(dftmp)],alpha = 0.5,zorder = 3)

                          # 添加注釋文字
                          for j,p in enumerate(dftmp.index):
                              px,py,pz = dftmp.loc[p,["x","y","z"]].tolist() 
                              if p in anotate_points:
                                  ax.annotate(p,xy = (px,py),  xycoords = "data",xytext = (-20,15),
                                  fontsize = 10,fontweight = "bold",color = cmap[j], textcoords = "offset points")
                                  
                      #繪制軌跡線
                      lines = [dfdata[["x","y"]].values[i:i+2for i in range(len(dfdata)-1)] 
                      for ln in lines[:-1]:
                          x, y = np.transpose(ln)
                          line = plt.Line2D(x,y,color="gray",linestyle="-",linewidth= 2.5)
                          ax.add_artist(line)
                      
                      # 添加標(biāo)題和排名序號
                      ax.set_title(title,color = "black",fontsize = 12)
                      ax.text(0.130.9, text, va="center", ha="center"
                                   alpha=0.5, size = 50,transform = ax.transAxes)
                      
                      # 結(jié)尾呈現(xiàn)全局軌跡無動畫
                      if i>=3*len(df):
                          for ln in lines[-1:]:
                              x, y = np.transpose(ln)
                              line = plt.Line2D(x,y,color="gray",linestyle="-",linewidth= 2.5)
                              ax.add_artist(line)
                          return 0

                      # 添加注意力動畫
                      if m==0:
                          px,py,pz = dfdata["x"][[-1]],dfdata["y"][[-1]],dfdata["z"][-1]
                          p = dfdata.index[-1]+":"+str(pz)+"Hours"
                          ax.scatter(px,py,s = 800*pz/df["z"].mean(),
                             c = cmap[len(dfdata)-1:len(dfdata)],alpha = 0.5,zorder = 4)
                          ax.annotate(p,xy = (px,py),  xycoords = "data",
                                  xytext = (-20,15),fontsize = 20,fontweight = "bold",
                                  color = cmap[k-1], textcoords = "offset points",zorder = 5)
                          
                          for ln in lines[-1:]:
                              x, y = np.transpose(ln)
                              line = plt.Line2D(x,y,color="gray",linestyle=":",linewidth= 4.5)
                              ax.add_artist(line)
                      
                      if m==1:
                          px,py,pz = dfdata["x"][[-1]],dfdata["y"][[-1]],dfdata["z"][-1]
                          p = dfdata.index[-1]+":"+str(pz)+"Hours"
                          ax.scatter(px,py,s = 400*pz/df["z"].mean(),
                             c = cmap[len(dfdata)-1:len(dfdata)],alpha = 0.5,zorder = 4)
                          ax.annotate(p,xy = (px,py),  xycoords = "data",
                                  xytext = (-20,15),fontsize = 15,fontweight = "bold",
                                  color = cmap[k-1], textcoords = "offset points",zorder = 5)
                          
                          for ln in lines[-1:]:
                              x, y = np.transpose(ln)
                              line = plt.Line2D(x,y,color="gray",linestyle="--",linewidth= 3.5)
                              ax.add_artist(line)
                          
                      if m==2:
                          px,py,pz = dfdata["x"][[-1]],dfdata["y"][[-1]],dfdata["z"][-1]
                          p = dfdata.index[-1]+":"+str(pz)+"Hours"
                          ax.scatter(px,py,s = 100*pz/df["z"].mean(),
                             c = cmap[len(dfdata)-1:len(dfdata)],alpha = 0.5,zorder = 4)
                          ax.annotate(p,xy = (px,py),  xycoords = "data",
                                  xytext = (-20,15),fontsize = 10,fontweight = "bold",
                                  color = cmap[k-1], textcoords = "offset points",zorder = 5)
                          
                          for ln in lines[-1:]:
                              x, y = np.transpose(ln)
                              line = plt.Line2D(x,y,color="gray",linestyle="-",linewidth= 2.5)
                              ax.add_artist(line)
                      return 0
                          
              my_animation = animation.FuncAnimation(fig,plot_frame,
                                      frames = range(0,3*len(df)+5),interval = int(duration*1000))
              
              if filename is None:
                  try:
                      from IPython.display import HTML
                      HTML(my_animation.to_jshtml())
                      return HTML(my_animation.to_jshtml())
                  except ImportError:
                      pass
              else:
                  my_animation.save(filename)
                  return filename

          html_file = "上海經(jīng)典4日旅行路線.html"
          trace_map_dance(df,filename=html_file)



          收工 。


              Python進階者最近搞了一個Python交流群,這個Python交流群已經(jīng)300多人了,有需要加入該群的小伙伴可以加我好友,一起學(xué)習(xí),共同進步。

          ------------------- End -------------------

          往期精彩文章推薦:

          歡迎大家點贊,留言,轉(zhuǎn)發(fā),轉(zhuǎn)載,感謝大家的相伴與支持

          想加入Python學(xué)習(xí)群請在后臺回復(fù)【入群

          萬水千山總是情,點個【在看】行不行

          /今日留言主題/

          隨便說一兩句吧~~

          瀏覽 43
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  影音先锋成人无码在线观看 | 99日精品 | 国产精品啪啪啪 | 蜜臀av一区二区 蜜芽av最新网址 | Safari帮我打开日韩av三级片 |