Пример #1
0
def create_bubble(temp_construct):
    figure = bubbleplot(dataset=temp_construct, x_column='deaths', y_column='confirmed', 
        bubble_column='region', time_column='date', size_column='confirmed', color_column='region', 
        x_title="deaths", y_title="Confirmed", title='Covid-19 Spread by top regions.',
        x_logscale=False, y_logscale=False, scale_bubble=1, height=650)

    figure.update
    return figure
Пример #2
0
def update_graph(value):
    #filter
    con = df[df['pc_name'] == value]
    total = con.groupby(['partyabbre',
                         'year']).sum()['totvotpoll'].reset_index(name='Total')
    ttitle = 'Peopel\'s choice in ' + value
    #plot
    figure = bubbleplot(dataset=total,
                        x_column='year',
                        y_column='Total',
                        bubble_column='partyabbre',
                        size_column='Total',
                        color_column='partyabbre',
                        x_title="Years",
                        y_title="Total Number of Votes",
                        title=ttitle,
                        x_range=['1977', '2014'],
                        marker_opacity=0.6)
    return figure
Пример #3
0
def BubblePlot():
    # 气泡图
    data = load_data()
    figure = bubbleplot(dataset=data,
                        x_column='SepalLengthCm',
                        y_column='PetalLengthCm',
                        z_column='SepalWidthCm',
                        bubble_column='Id',
                        size_column='PetalWidthCm',
                        color_column='Species',
                        x_title='SepalLength(Cm)',
                        y_title='PetalLength(Cm)',
                        z_title='SepalWidth(Cm)',
                        title='IRIS Visualization',
                        x_logscale=False,
                        scale_bubble=0.1,
                        height=600)
    iplot(figure, config={'scrollzoom': True})
    plt.show()
    return
Пример #4
0
def animated_bubble_chart(year_range, month_range, si_range, area_range, map_size_radio_items, hours_range,
                          country_list):
    tmp = filter_events(year_range, month_range, si_range, area_range, map_size_radio_items, hours_range, country_list)

    tmp = tmp[['event_id', 'event_year', 'country', 'meanPre', 'size', 'area']].groupby(
        ['event_id', 'event_year', 'country']).sum(['meanPre', 'size', 'area']).reset_index()
    tmp['event_year'] = pd.to_datetime(tmp['event_year'], format='%Y')

    tmp3 = pd.DataFrame()

    for country in list(tmp.country.unique()):
        tmp2 = tmp[tmp['country'] == country]
        tmp2 = tmp2.append({'event_year': tmp['event_year'].min(), 'meanPre': 0, 'size': 0, 'area': 0},
                           ignore_index=True)
        tmp2 = tmp2.append({'event_year': tmp['event_year'].max(), 'meanPre': 0, 'size': 0, 'area': 0},
                           ignore_index=True)
        tmp2 = tmp2.groupby(pd.Grouper(key='event_year', freq='Y')).sum(['size']).reset_index()
        tmp2 = tmp2.fillna(0)
        tmp2['country'] = country
        tmp3 = tmp3.append(tmp2)

    tmp = tmp3.reset_index(drop=True)
    tmp['event_year'] = tmp['event_year'].dt.year
    tmp['Country_Name'] = 'Other'
    tmp.loc[tmp['country'] == 'IT', 'Country_Name'] = 'Italy'
    tmp.loc[tmp['country'] == 'DE', 'Country_Name'] = 'Germany'
    tmp.loc[tmp['country'] == 'PL', 'Country_Name'] = 'Poland'
    tmp.loc[tmp['country'] == 'CZ', 'Country_Name'] = 'Czech Republic'
    tmp.loc[tmp['country'] == 'TN', 'Country_Name'] = 'Tunesia'
    tmp = tmp[tmp['country'] != 'INT']

    figure = bubbleplot(dataset=tmp, x_column='area', y_column='meanPre',
                        bubble_column='country', time_column='event_year', size_column='size',
                        color_column='Country_Name',
                        x_title="Total Area", y_title="Total Precipitation",
                        title='Heavy Rain Events in selected Countries')

    return figure
#%%
#filter the dataframe according to u_input

traces = plotly.graph_objs.Scatter(x=acum_text[:10]['word'],
                                   y=acum_text[:10]['count'],
                                   mode='lines')

layout = plotly.graph_objs.Layout(xaxis=dict(
    tickvals=acum_text[:10]['word'].unique()))
fig = plotly.graph_objs.Figure(data=traces, layout=layout)

plotly.offline.plot(fig)

#%%

figure = bubbleplot(dataset=acum_text,
                    x_column='count',
                    y_column='count',
                    bubble_column='count',
                    size_column='count',
                    color_column='word',
                    x_title="Palabras",
                    y_title="Repeticiones",
                    title='Palabras en la constitucion',
                    x_logscale=True,
                    scale_bubble=3,
                    height=650)

plot(figure, filename="holi.html")
# In[46]:

# Visaulizing the clusters with respect to economy, corruption, gdp, rank and their scores

from bubbly.bubbly import bubbleplot

figure = bubbleplot(
    dataset=happy_df_cluster,
    x_column='GDP per capita',
    y_column='Perceptions of corruption',
    bubble_column='Country or region',
    color_column='cluster',
    z_column='Healthy life expectancy',
    size_column='Score',
    x_title="GDP per capita",
    y_title="Corruption",
    z_title="Life Expectancy",
    title=
    'Clusters based Impact of Economy, Corruption and Life expectancy on Happiness Scores of Nations',
    colorbar_title='Cluster',
    marker_opacity=1,
    colorscale='Portland',
    scale_bubble=0.8,
    height=650)

iplot(figure, config={'scrollzoom': True})

# In[47]:

# Visualizing the clusters geographically
data = dict(type='choropleth',
Пример #7
0
#在total1加入老年人口比率、人口密度及都市化程度的欄位
total1.insert(3,
              column="老年人口比率(%)",
              value=round(((total1['老年人口數'] / total1['總人口數']) * 100), 2))
total1.insert(5,
              column='人口密度',
              value=round(total1['總人口數'] / total1['面積(Km²)'], 2))
total1.insert(6, column='都市化程度', value=round(np.log(total1['人口密度']), 2))

#畫出新北市各區都市化程度與老年人口比相關泡泡圖
figure = bubbleplot(dataset=total1,
                    x_column='都市化程度',
                    y_column='老年人口比率(%)',
                    bubble_column='行政區',
                    size_column='老年人口數',
                    color_column='行政區',
                    x_title='都市化程度(以人口密度取自然對數為都市化指標)',
                    y_title='老年人口比',
                    title='新北市各區都市化程度與老年人口比相關泡泡圖',
                    x_logscale=True,
                    scale_bubble=1,
                    height=600)
plot(figure, config={'scrollzoom': True})

#依照泡泡圖的都市化程度結果對行政區分組
total1.insert(0, column='行政區1', value=total1['行政區'])
total1 = total1.set_index('行政區')
total1 = total1.rename(columns={'行政區1': '行政區'})
#g1組:平溪、雙溪、坪林、貢寮、石碇、烏來
g1 = total1.ix[['平溪區', '雙溪區', '坪林區', '貢寮區', '石碇區', '烏來區']]
#g2組:瑞芳、三芝、石門、三峽、金山、萬里、八里
g2 = total1.ix[['三芝區', '石門區', '三峽區', '金山區', '萬里區', '八里區', '瑞芳區']]
data.head()
# describing the data

data.describe()
profile = pandas_profiling.ProfileReport(data)
profile
import warnings
warnings.filterwarnings('ignore')

figure = bubbleplot(dataset=data,
                    x_column='trestbps',
                    y_column='chol',
                    bubble_column='sex',
                    time_column='age',
                    size_column='oldpeak',
                    color_column='sex',
                    x_title="Resting Blood Pressure",
                    y_title="Cholestrol",
                    title='BP vs Chol. vs Age vs Sex vs Heart Rate',
                    x_logscale=False,
                    scale_bubble=3,
                    height=650)

py.iplot(figure, config={'scrollzoom': True})
# making a heat map

plt.rcParams['figure.figsize'] = (20, 15)
plt.style.use('ggplot')

sns.heatmap(data.corr(), annot=True, cmap='Wistia')
plt.title('Heatmap for the Dataset', fontsize=20)
Пример #9
0
fig = ff.create_distplot(pk_list, group_labels, bin_size=5)
fig['layout'].update(title='Distribution of All Pokemon Stats')
py.iplot(fig, filename='distplot', validate=False)
plotly.offline.plot(fig, filename="plotly_5.html")
###############################################################################

### Plotly Visual 6 ###########################################################
###############################################################################
from bubbly.bubbly import bubbleplot
df_bb = pd.read_csv('suicide_data.csv')
df_bb = df_bb.sort_values(by=['year'])
df_bb['rate'] = df_bb['suicides_no'] / df_bb['population']

figure = bubbleplot(
    dataset=df_bb,
    x_column='population',
    y_column='suicides_no',
    bubble_column='country',
    time_column='year',
    size_column='suicides_no',
    color_column='age',
    x_title="Population",
    y_title="Suicides Number",
    title='Suicides/Population Bubble Plot by Age Groups 1979-2016',
    x_logscale=True,
    scale_bubble=3,
    height=650)

py.iplot(figure, filename='nbplot', validate=False)
plotly.offline.plot(figure, filename="plotly_6.html")
###############################################################################
Пример #10
0
# Checking if there is any null values left
SS['suicides'] = SS['suicides'].astype(int)
SS['population'] = SS['population'].astype(int)

# DATA VISUALIZATION
# In[11]:


import warnings
warnings.filterwarnings('ignore')

figure = bubbleplot(dataset = SS,
            x_column = 'suicides',
            y_column = 'population',
            bubble_column = 'country',
            color_column =  'country', 
            x_title = 'Number of Suicides', 
            y_title = 'Population', 
            title = 'Population and Suicides',
            x_logscale = False, 
            scale_bubble= 1, height = 550)

py.iplot(figure, config = {'scrollzom' : True})

# In this plot, regions such as Africa and Asia are high as compared to U.S. and Europe
# In[12]:


# Visualization of the different countries distribution

plt.style.use('seaborn-dark')
plt.rcParams['figure.figsize'] = (15, 9)
Пример #11
0
marvel['FIRST APPEARANCE'].fillna(marvel['FIRST APPEARANCE'].mode()[0],
                                  inplace=True)
marvel['Year'].fillna(marvel['Year'].mode()[0], inplace=True)

import warnings
warnings.filterwarnings('ignore')

dc['YEAR'] = dc['YEAR'].astype(int)
dc['APPEARANCES'] = dc['APPEARANCES'].astype(int)

figure = bubbleplot(dataset=marvel,
                    x_column='APPEARANCES',
                    y_column='Year',
                    bubble_column='ALIGN',
                    size_column='APPEARANCES',
                    color_column='ALIGN',
                    y_title="Appearances",
                    x_title="Year",
                    title='Year VS ALIGNMENT VS APPEARANCES',
                    x_logscale=False,
                    scale_bubble=3,
                    height=650)

py.iplot(figure, config={'scrollzoom': True})

plt.style.use('fivethirtyeight')
plt.rcParams['figure.figsize'] = (20, 10)

plt.subplot(2, 1, 1)
sns.violinplot(dc['ID'], dc['YEAR'], hue=dc['ALIGN'], palette='PuRd')
plt.xlabel(' ')
plt.title('DC', fontsize=30)
Пример #12
0
])

data.shape

data.head(25)

profile = pandas_profiling.ProfileReport(data)
profile

award_names = {
    'Best Director': 1,
    'Best Actor': 2,
    'Best Supporting Actor': 3,
    'Best Actress': 4,
    'Best Supporting Actress': 5
}
data['awards'] = data.award.map(award_names)

data.columns

data.head()

visualization = bubbleplot(data,
                           x_column='awards',
                           y_column='_trusted_judgments',
                           bubble_column='race_ethnicity',
                           time_column='year_of_award')
py.iplot(visualization, config={'scrollzoom': True})

pd.crosstab([data.year_of_award], data._trusted_judgments)
Пример #13
0
import plotly.offline as py
from plotly.offline import init_notebook_mode, iplot

import plotly.graph_objs as go

import Clean as cl
data = pd.read_csv("europe.csv")

# Following are the codes for various bubbleplot generated using iplot
# The only thing changing is the column names and their values.
figure = bubbleplot(dataset=data,
                    x_column='gdp',
                    y_column='prct_job_satis_high',
                    bubble_column='country',
                    size_column='total_pop',
                    color_column='country',
                    x_title="GDP",
                    y_title="Job Satisfaction",
                    title='GDP vs Job vs Population',
                    x_logscale=True,
                    scale_bubble=3,
                    height=650)
iplot(figure)

figure = bubbleplot(dataset=data,
                    x_column='prct_life_satis_high',
                    y_column='prct_env_satis_high',
                    bubble_column='country',
                    size_column='gdp',
                    color_column='country',
                    x_title="Life Satisfaction",
                    y_title="Environment Satisfaction",