Plotting by plot_matrix
mario has a generic plot function for plotting the matrices that follows the main rule of the plotly express functions. This function gives the ability to the user to plot basic functions for differnet matrices and different scnearios with a given degree of freedom. In the following example, a couple of examples are represented on IOT and SUT datbases.
IOT Example¶
In [1]:
import mario
In [2]:
# loading a IOT test
test = mario.load_test('IOT')
In [3]:
# plotting total final demand matrix with plot_matrix without separating the regions
test.plot_matrix(
matrix= 'Y',
x = 'Consumption_category', # putting the consumtion categoreis on x axis
color= 'Sector_from', # the colors will define the sectors that consumption categroies coming from,
path= 'final_deamnd.html'
)
In [4]:
# specifying the origin of the final demands and the destinations by facet_row and facet_col
# the following plot defines the consumption of sector outputs from regions to different regions
test.plot_matrix(
matrix = 'Y',
x = 'Consumption_category',
color = 'Sector_from',
facet_row = 'Region_from',
facet_col = 'Region_to',
path= 'final_comnsumtpiton_by_region.html'
)
In [5]:
# User also have the degree of freedom to change the color palettes to another mario default palette or a costumized palette
mario.set_palette('McKinsey')
In [6]:
# User may also filter different sets of the database such as specifying specific sectors or consumption categories by using filters
# In this example, sectors_from (reprsenting the origin/producing sector) is filtered and the origin and destination region also limited
# to Italy
test.plot_matrix(
matrix = 'Y',
x = 'Consumption_category',
color = 'Sector_from',
facet_row = 'Region_from',
facet_col = 'Region_to',
filter_Sector_from = ['Agriculture',
'Mining',
'Services'],
filter_Region_from= ['Italy'],
filter_Region_to = ['Italy'],
path='Italy_final_demand.html'
)
SUT Example¶
In [7]:
test = mario.load_test('SUT')
the sut load_test is a two regions database (Italy, RoW). In order to pot the total use of commodities originated from Italy, the plot_matrix function can be used as follow
In [8]:
test.plot_matrix(
matrix = 'U', # plotting the use flow,
x = 'Item_to', # What to represent on the main items to be plotted on the x axis (in this case, items to the consumption origins)
color = 'Sector_from', # the production sectors define the colors
facet_row = 'Region_from', # specifying the facet rows by region originated
facet_col = 'Region_to', # specifying the facet cols by region consumed,
path='Use flows.html'
)
In [9]:
# plotting the value added
test.plot_matrix(
matrix = 'V', # plotting the value added,
x = 'Factor of production', # What to represent on the main items to be plotted on the x axis (in this case, items to the consumption origins)
color='Activity_to',
path='value added.html',
)
In [ ]: