import pandas_alive
import pandas as pd
import matplotlib.pyplot as plt
# 中文显示
plt.rcParams['font.sans-serif'] = ['SimHei'] # Windows
plt.rcParams['font.sans-serif'] = ['Hiragino Sans GB'] # Mac
plt.rcParams['axes.unicode_minus'] = False
# 读取数据
df_result = pd.read_csv('data/yuhuanshui.csv', index_col=0, parse_dates=[0])
# 生成图表
animated_line_chart = df_result.diff().fillna(0).plot_animated(kind='line', period_label=False, add_legend=False)
animated_bar_chart = df_result.plot_animated(n_visible=10)
pandas_alive.animate_multiple_plots('examples/yuhuanshui.gif',
[animated_bar_chart, animated_line_chart], enable_progress_bar=True,
title='我是余欢水演职人员热度排行')
# covid_df = pd.read_csv('data/covid19.csv', index_col=0, parse_dates=[0])
# covid_df.plot_animated(filename='examples/example-barh-chart.gif', n_visible=15)
# elec_df = pd.read_csv("data/Aus_Elec_Gen_1980_2018.csv", index_col=0, parse_dates=[0], thousands=',')
# elec_df = elec_df.iloc[:20, :]
# elec_df.fillna(0).plot_animated('examples/example-electricity-generated-australia.gif', period_fmt="%Y",
# title='Australian Electricity Generation Sources 1980-2018')
# covid_df = pd.read_csv('data/covid19.csv', index_col=0, parse_dates=[0])
# covid_df.diff().fillna(0).plot_animated(filename='examples/example-line-chart.gif', kind='line', period_label={'x': 0.25, 'y': 0.9})
# covid_df = pd.read_csv('data/covid19.csv', index_col=0, parse_dates=[0])
# covid_df.sum(axis=1).fillna(0).plot_animated(filename='examples/example-bar-chart.gif', kind='bar',
# period_label={'x': 0.1, 'y': 0.9},
# enable_progress_bar=True, steps_per_period=2, interpolate_period=True, period_length=200
# )
def scatter_chart():
max_temp_df = pd.read_csv(
"data/Newcastle_Australia_Max_Temps.csv",
parse_dates={"Timestamp": ["Year", "Month", "Day"]},
)
min_temp_df = pd.read_csv(
"data/Newcastle_Australia_Min_Temps.csv",
parse_dates={"Timestamp": ["Year", "Month", "Day"]},
)
max_temp_df = max_temp_df.iloc[:5000, :]
min_temp_df = min_temp_df.iloc[:5000, :]
merged_temp_df = pd.merge_asof(max_temp_df, min_temp_df, on="Timestamp")
merged_temp_df.index = pd.to_datetime(merged_temp_df["Timestamp"].dt.strftime('%Y/%m/%d'))
keep_columns = ["Minimum temperature (Degree C)", "Maximum temperature (Degree C)"]
merged_temp_df[keep_columns].resample("Y").mean().plot_animated(filename='examples/example-scatter-chart.gif',
kind="scatter",
title='Max & Min Temperature Newcastle, Australia')
def pie_chart():
covid_df = pd.read_csv('data/covid19.csv', index_col=0, parse_dates=[0])
covid_df.plot_animated(filename='examples/example-pie-chart.gif', kind="pie",
rotatelabels=True, period_label={'x': 0, 'y': 0})
def buddle_chart():
multi_index_df = pd.read_csv("data/multi.csv", header=[0, 1], index_col=0)
multi_index_df.index = pd.to_datetime(multi_index_df.index, dayfirst=True)
map_chart = multi_index_df.plot_animated(
kind="bubble",
filename="examples/example-bubble-chart.gif",
x_data_label="Longitude",
y_data_label="Latitude",
size_data_label="Cases",
color_data_label="Cases",
vmax=5, steps_per_period=3, interpolate_period=True, period_length=500,
dpi=100
)
def geo_point_chart():
import geopandas
import pandas_alive
import contextily
gdf = geopandas.read_file('data/nsw-covid19-cases-by-postcode.gpkg')
gdf.index = gdf.postcode
gdf = gdf.drop('postcode', axis=1)
result = gdf.iloc[:, :20]
result['geometry'] = gdf.iloc[:, -1:]['geometry']
map_chart = result.plot_animated(filename='examples/example-geo-point-chart.gif',
basemap_format={'source': contextily.providers.Stamen.Terrain})
def geo_polygon_chart():
import geopandas
import pandas_alive
import contextily
gdf = geopandas.read_file('data/italy-covid-region.gpkg')
gdf.index = gdf.region
gdf = gdf.drop('region', axis=1)
result = gdf.iloc[:, :20]
result['geometry'] = gdf.iloc[:, -1:]['geometry']
map_chart = result.plot_animated(filename='examples/example-geo-polygon-chart.gif',
basemap_format={'source': contextily.providers.Stamen.Terrain})
def bar_and_line_chart():
covid_df = pd.read_csv('data/covid19.csv', index_col=0, parse_dates=[0])
animated_line_chart = covid_df.diff().fillna(0).plot_animated(kind='line', period_label=False, add_legend=False)
animated_bar_chart = covid_df.plot_animated(n_visible=10)
pandas_alive.animate_multiple_plots('examples/example-bar-and-line-chart.gif',
[animated_bar_chart, animated_line_chart], enable_progress_bar=True)
def population():
urban_df = pd.read_csv("data/urban_pop.csv", index_col=0, parse_dates=[0])
animated_line_chart = (
urban_df.sum(axis=1)
.pct_change()
.fillna(method='bfill')
.mul(100)
.plot_animated(kind="line", title="Total % Change in Population", period_label=False, add_legend=False)
)
animated_bar_chart = urban_df.plot_animated(n_visible=10, title='Top 10 Populous Countries', period_fmt="%Y")
pandas_alive.animate_multiple_plots('examples/example-bar-and-line-urban-chart.gif',
[animated_bar_chart, animated_line_chart],
title='Urban Population 1977 - 2018', adjust_subplot_top=0.85,
enable_progress_bar=True)
# population()
def life():
data_raw = pd.read_csv("data/long.csv")
list_G7 = [
"Canada",
"France",
"Germany",
"Italy",
"Japan",
"United Kingdom",
"United States",
]
data_raw = data_raw.pivot(
index="Year", columns="Entity", values="Life expectancy (Gapminder, UN)"
)
data = pd.DataFrame()
data["Year"] = data_raw.reset_index()["Year"]
for country in list_G7:
data[country] = data_raw[country].values
data = data.fillna(method="pad")
data = data.fillna(0)
data = data.set_index("Year").loc[1900:].reset_index()
data["Year"] = pd.to_datetime(data.reset_index()["Year"].astype(str))
data = data.set_index("Year")
data = data.iloc[:25, :]
animated_bar_chart = data.plot_animated(
period_fmt="%Y", perpendicular_bar_func="mean", period_length=200, fixed_max=True
)
animated_line_chart = data.plot_animated(
kind="line", period_fmt="%Y", period_length=200, fixed_max=True
)
pandas_alive.animate_multiple_plots(
"examples/life-expectancy.gif",
plots=[animated_bar_chart, animated_line_chart],
title="Life expectancy in G7 countries up to 2015",
adjust_subplot_left=0.2, adjust_subplot_top=0.9, enable_progress_bar=True
)
# life()
def nsw():
import geopandas
import pandas as pd
import pandas_alive
import contextily
import matplotlib.pyplot as plt
import json
with open('data/package_show.json', 'r', encoding='utf8')as fp:
data = json.load(fp)
# Extract url to csv component
covid_nsw_data_url = data["result"]["resources"][0]["url"]
print(covid_nsw_data_url)
# Read csv from data API url
nsw_covid = pd.read_csv('data/confirmed_cases_table1_location.csv')
postcode_dataset = pd.read_csv("data/postcode-data.csv")
# Prepare data from NSW health dataset
nsw_covid = nsw_covid.fillna(9999)
nsw_covid["postcode"] = nsw_covid["postcode"].astype(int)
grouped_df = nsw_covid.groupby(["notification_date", "
没有合适的资源?快使用搜索试试~ 我知道了~
Python可视化图库绘制动态图表源码
共24个文件
csv:12个
gpkg:2个
shx:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 166 浏览量
2024-04-28
19:44:54
上传
评论
收藏 1.98MB ZIP 举报
温馨提示
可视化图库Pandas_Alive实现动态图表绘制,使用时减少数据会使生成GIF的时间变短。通过对CSV文件分析,实现动态条形图、动态曲线图、气泡图、饼状图、地理空间图等多个动态图表的可视化分析。
资源推荐
资源详情
资源评论
收起资源包目录
动态图表.zip (24个子文件)
动态图表
pendulum_sample.ipynb 124KB
data
Newcastle_Australia_Max_Temps.csv 857KB
geo-data
italy-with-regions
reg2011_g.sbx 132B
reg2011_g.shp 1.19MB
reg2011_g.dbf 2KB
reg2011_g.shp.xml 7KB
reg2011_g.shx 260B
reg2011_g.sbn 316B
reg2011_g.prj 412B
Aus_Elec_Gen_1980_2018.csv 2KB
nsw-covid-cases-by-postcode.csv 20KB
covid19.csv 1KB
Newcastle_Australia_Min_Temps.csv 853KB
Regional Data - Sheet1.csv 120KB
confirmed_cases_table1_location.csv 241KB
package_show.json 6KB
yuhuanshui.csv 1016B
multi.csv 318KB
nsw-covid19-cases-by-postcode.gpkg 860KB
postcode-data.csv 749KB
long.csv 1.05MB
urban_pop.csv 7KB
italy-covid-region.gpkg 1.31MB
alive_chart.py 26KB
共 24 条
- 1
资源评论
python慕遥
- 粉丝: 2288
- 资源: 240
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功