id,node_id,number,title,user,state,locked,assignee,milestone,comments,created_at,updated_at,closed_at,author_association,active_lock_reason,draft,pull_request,body,reactions,performed_via_github_app,state_reason,repo,type 2066367459,PR_kwDOAMm_X85jQuAO,8588,Update ecosystem.rst,109167,closed,0,,,3,2024-01-04T21:34:24Z,2024-01-04T22:41:06Z,2024-01-04T22:41:03Z,CONTRIBUTOR,,0,pydata/xarray/pulls/8588,"Related https://github.com/JuliaDataCubes/YAXArrays.jl/issues/354 - [ ] Closes #xxxx - [ ] Tests added - [ ] User visible changes (including notable bug fixes) are documented in `whats-new.rst` - [ ] New functions/methods are listed in `api.rst` ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/8588/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull 137517563,MDU6SXNzdWUxMzc1MTc1NjM=,779,ENH: Mosaic plot and DataArray,109167,closed,0,,,4,2016-03-01T09:16:52Z,2016-03-02T08:07:13Z,2016-03-02T08:07:13Z,CONTRIBUTOR,,,,"Hello, I'd like to draw using Python a similar mosaic plot (also named Marimekko chart) of R dataset `HairEyeColor`. https://github.com/wch/r-source/blob/trunk/src/library/datasets/data/HairEyeColor.R Here is R code ``` R > library(datasets) > HairEyeColor , , Sex = Male Eye Hair Brown Blue Hazel Green Black 32 11 10 3 Brown 53 50 25 15 Red 10 10 7 7 Blond 3 30 5 8 , , Sex = Female Eye Hair Brown Blue Hazel Green Black 36 9 5 2 Brown 66 34 29 14 Red 16 7 7 7 Blond 4 64 5 8 ``` I can display a mosaic plot using R with the following example available thanks to `?HairEyeColor` ``` R require(graphics) ## Full mosaic mosaicplot(HairEyeColor) ## Aggregate over sex (as in Snee's original data) x <- apply(HairEyeColor, c(1, 2), sum) x mosaicplot(x, main = ""Relation between hair and eye color"") ``` I get: ![r_mosaic_plot_haireyecolor](https://cloud.githubusercontent.com/assets/109167/13425003/6ddb5f6e-dfa4-11e5-94ee-695beba91c5a.png) I try to produce a similar plot using Python. I created `xarray.DataArray` using: ``` python import numpy as np import xarray data = np.array([32, 53, 10, 3, 11, 50, 10, 30, 10, 25, 7, 5, 3, 15, 7, 8, 36, 66, 16, 4, 9, 34, 7, 64, 5, 29, 7, 5, 2, 14, 7, 8]) _dim = (4, 4, 2) data = data.reshape(_dim[::-1]) _dims = ['Hair', 'Eye', 'Sex'] _coords = [['Black', 'Brown', 'Red', 'Blond'], ['Brown', 'Blue', 'Hazel', 'Green'], ['Male', 'Female']] data = xarray.DataArray( data, dims=_dims[::-1], coords=_coords[::-1], name='Number' ) assert int(data.loc['Female', 'Green', 'Black']) == 2 ``` and try to plot mosaic using: ``` python import matplotlib.pyplot as plt from statsmodels.graphics.mosaicplot import mosaic mosaic(data) plt.show() ``` I get: ![python_mosaic_plot](https://cloud.githubusercontent.com/assets/109167/13422618/399aaeca-df96-11e5-9829-8416e1b4d904.png) I think there is some room for improvements. Providing a `da.plot.mosaic` method may be a first feature. Using labels will be an other interesting feature. Kind regards PS: a similar mosaic plot can be plot using Titanic dataset https://github.com/wch/r-source/blob/trunk/src/library/datasets/data/Titanic.R with R ![r_mosaic_plot_titanic](https://cloud.githubusercontent.com/assets/109167/13424971/2e5d1fda-dfa4-11e5-8c3d-644f0f6d32f7.png) with Python ``` python import numpy as np import xarray data = np.array([ 0, 0, 35, 0, 0, 0, 17, 0, 118, 154, 387, 670, 4, 13, 89, 3, 5, 11, 13, 0, 1, 13, 14, 0, 57, 14, 75, 192, 140, 80, 76, 20]) _dim = (4, 2, 2, 2) data = data.reshape(_dim[::-1]) _dims = ['Class', 'Sex', 'Age', 'Survived'] _coords = [['1st', '2nd', '3rd', 'Crew'], ['Male', 'Female'], ['Child', 'Adult'], ['No', 'Yes']] data = xarray.DataArray( data, dims=_dims[::-1], coords=_coords[::-1], name='Number' ) assert int(data.loc['Yes', 'Adult', 'Male', '3rd']) == 75 ``` ![python_mosaic_plot_titanic](https://cloud.githubusercontent.com/assets/109167/13424975/3307159a-dfa4-11e5-8f9f-94a04169f50d.png) PS2: Python/xarray datasets are available at https://github.com/Rdatasets/python PS3: mosaic code can be found here: https://github.com/statsmodels/statsmodels/blob/master/statsmodels/graphics/mosaicplot.py https://github.com/statsmodels/statsmodels/blob/master/statsmodels/graphics/tests/test_mosaicplot.py ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/779/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue