# Windrose legend issue

**URL:** <https://discourse.pollination.solutions/t/windrose-legend-issue/3525>\
**Category:** Web platform\
**Tags:** bug-report\
**Created:** [January 21, 2024, 3:12am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525 "2024-01-21T03:12:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [January 21, 2024, 3:12am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/1 "2024-01-21T03:12:41Z")

</div>

There is also another issue with LegendParameters - the minimum and maximum functions do not work - this can be a new topic though -

```auto
with st.expander('Windrose'):
    
        windrose_st_month = st.number_input(
            'Start month', min_value=1, max_value=12, value=1, key='windrose_st_month')
        windrose_end_month = st.number_input(
            'End month', min_value=1, max_value=12, value=12, key='windrose_end_month')

        windrose_st_day = st.number_input(
            'Start day', min_value=1, max_value=31, value=1, key='windrose_st_day')
        windrose_end_day = st.number_input(
            'End day', min_value=1, max_value=31, value=31, key='windrose_end_day')

        windrose_st_hour = st.number_input(
            'Start hour', min_value=0, max_value=23, value=0, key='windrose_st_hour')
        windrose_end_hour = st.number_input(
            'End hour', min_value=0, max_value=23, value=23, key='windrose_end_hour')

def get_windrose_figure_temp(st_month: int, st_day: int, st_hour: int, end_month: int,
                    end_day: int, end_hour: int, _epw, global_colorset) -> Figure:
    
    """Create windrose figure.
    Args:
        st_month: A number representing the start month.
        st_day: A number representing the start day.
        st_hour: A number representing the start hour.
        end_month: A number representing the end month.
        end_day: A number representing the end day.
        end_hour: A number representing the end hour.
        epw: An EPW object.
        global_colorset: A string representing the name of a Colorset.
    Returns:
        A plotly figure.
    """
    
    lb_ap = AnalysisPeriod(st_month, st_day, st_hour, end_month, end_day, end_hour)        
    
    fields = get_fields()
        
    windrose_data = SI_IP_Check(_epw.import_data_by_field(fields['Dry Bulb Temperature']))
    
    wind_dir = _epw.wind_direction.filter_by_analysis_period(lb_ap)
    windrose_dbt_ = windrose_data.filter_by_analysis_period(lb_ap)
    
    lb_lp = LegendParameters(colors=colorsets[global_colorset], max = 60)
    
    lb_windrose_temp = WindRose(wind_dir,windrose_dbt_)
    lb_windrose_temp.legend_parameters = lb_lp
    
    return lb_windrose_temp.plot(title='Wind Direction vs. Dry Bulb Temperature', show_title=True)

windrose_figure_temp = get_windrose_figure_temp(windrose_st_month, windrose_st_day, windrose_st_hour, windrose_end_month,
                                              windrose_end_day, windrose_end_hour, global_epw, global_colorset)

st.plotly_chart(windrose_figure_temp, use_container_width=True,
                        config=get_figure_config(f'Windrose_{global_epw.location.city}'))
    

```

![image](https://discourse.pollination.cloud/uploads/default/original/2X/b/ba4218c79f2f1e42fceb51f08b521fc63a90e7dc.png)

---

<div class="post-metadata">

**Author:** ![devang](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/devang/32/9082_2.png) [@devang](https://discourse.pollination.solutions/u/devang)\
**Post date:** [January 22, 2024, 1:15am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/2 "2024-01-22T01:15:34Z")

</div>

Can you please share a minimum complete script that I can use to re-produce the issue. A minimum complete script will have all the necessary libraries and functions imported.

What you shared seems like a snippet from your Streamlit app. I could not get it to work right away.

---

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [January 22, 2024, 1:47am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/3 "2024-01-22T01:47:49Z")

</div>

Thanks @devang - I hope this helps

```auto
from ladybug.windrose import WindRose
from ladybug.analysisperiod import AnalysisPeriod
from ladybug.legend import LegendParameters
from ladybug.epw import EPWFields
from ladybug.color import Colorset, Color
from ladybug.datacollection import HourlyContinuousCollection

epw_file = './assets/sample.epw'

global_epw = EPW(epw_file)

@st.cache_data(ttl=2)
def get_windrose_figure_temp(st_month: int, st_day: int, st_hour: int, end_month: int,
                    end_day: int, end_hour: int, _epw, global_colorset) -> Figure:
    
    """Create windrose figure.
    Args:
        st_month: A number representing the start month.
        st_day: A number representing the start day.
        st_hour: A number representing the start hour.
        end_month: A number representing the end month.
        end_day: A number representing the end day.
        end_hour: A number representing the end hour.
        epw: An EPW object.
        global_colorset: A string representing the name of a Colorset.
    Returns:
        A plotly figure.
    """
    
    lb_ap = AnalysisPeriod(st_month, st_day, st_hour, end_month, end_day, end_hour)        
    
    fields = get_fields()
        
    windrose_data = _epw.import_data_by_field(fields['Dry Bulb Temperature'])
    
    wind_dir = _epw.wind_direction.filter_by_analysis_period(lb_ap)
    windrose_dbt_ = windrose_data.filter_by_analysis_period(lb_ap)
    
    lb_lp = LegendParameters(colors=colorsets[global_colorset], max = 60)
    
    lb_windrose_temp = WindRose(wind_dir,windrose_dbt_)
    lb_windrose_temp.legend_parameters = lb_lp
    
    return lb_windrose_temp.plot(title='Wind Direction vs. Dry Bulb Temperature', show_title=True)

windrose_figure_temp = get_windrose_figure_temp(windrose_st_month, windrose_st_day, windrose_st_hour, windrose_end_month,
                                              windrose_end_day, windrose_end_hour, global_epw, global_colorset)
    
        st.plotly_chart(windrose_figure_temp, use_container_width=True,
                        config=get_figure_config(f'Windrose_{global_epw.location.city}'))

```

---

<div class="post-metadata">

**Author:** ![devang](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/devang/32/9082_2.png) [@devang](https://discourse.pollination.solutions/u/devang)\
**Post date:** [January 23, 2024, 1:44am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/4 "2024-01-23T01:44:21Z")

</div>

Not. It wasn’t a complete minimum script that someone can use right away. Fortunately, I knew that you had used functions from the Weather-report app. So I could get the functions.

Following is an example of a complete minimum script that anyone can just use.

```auto
import streamlit as st
from ladybug.windrose import WindRose
from ladybug.analysisperiod import AnalysisPeriod
from ladybug.legend import LegendParameters
from ladybug.epw import EPWFields
from ladybug.epw import EPW
from ladybug.color import Colorset
from plotly.graph_objs import Figure

epw_file = 'path to EPW file'
global_epw = EPW(epw_file)

def get_fields() -> dict:
    # A dictionary of EPW variable name to its corresponding field number
    return {EPWFields._fields[i]['name'].name: i for i in range(6, 34)}

colorsets = {
    'original': Colorset.original(),
    'nuanced': Colorset.nuanced(),
    'annual_comfort': Colorset.annual_comfort(),
    'benefit': Colorset.benefit(),
    'benefit_harm': Colorset.benefit_harm(),
    'black_to_white': Colorset.black_to_white(),
    'blue_green_red': Colorset.blue_green_red(),
    'cloud_cover': Colorset.cloud_cover(),
    'cold_sensation': Colorset.cold_sensation(),
    'ecotect': Colorset.ecotect(),
    'energy_balance': Colorset.energy_balance(),
    'energy_balance_storage': Colorset.energy_balance_storage(),
    'glare_study': Colorset.glare_study(),
    'harm': Colorset.harm(),
    'heat_sensation': Colorset.heat_sensation(),
    'multi_colored': Colorset.multi_colored(),
    'multicolored_2': Colorset.multicolored_2(),
    'multicolored_3': Colorset.multicolored_3(),
    'openstudio_palette': Colorset.openstudio_palette(),
    'peak_load_balance': Colorset.peak_load_balance(),
    'shade_benefit': Colorset.shade_benefit(),
    'shade_benefit_harm': Colorset.shade_benefit_harm(),
    'shade_harm': Colorset.shade_harm(),
    'shadow_study': Colorset.shadow_study(),
    'therm': Colorset.therm(),
    'thermal_comfort': Colorset.thermal_comfort(),
    'view_study': Colorset.view_study()
}

def get_figure_config(title: str) -> dict:
    """Set figure config so that a figure can be downloaded as SVG."""

    return {
        'toImageButtonOptions': {
            'format': 'svg', # one of png, svg, jpeg, webp
            'filename': title,
            'height': 350,
            'width': 700,
            'scale': 1 # Multiply title/legend/axis/canvas sizes by this factor
        }
    }

global_colorset = colorsets['original']

with st.expander('Windrose'):
    windrose_st_month = st.number_input(
        'Start month', min_value=1, max_value=12, value=1, key='windrose_st_month')
    windrose_end_month = st.number_input(
        'End month', min_value=1, max_value=12, value=12, key='windrose_end_month')

    windrose_st_day = st.number_input(
        'Start day', min_value=1, max_value=31, value=1, key='windrose_st_day')
    windrose_end_day = st.number_input(
        'End day', min_value=1, max_value=31, value=31, key='windrose_end_day')

    windrose_st_hour = st.number_input(
        'Start hour', min_value=0, max_value=23, value=0, key='windrose_st_hour')
    windrose_end_hour = st.number_input(
        'End hour', min_value=0, max_value=23, value=23, key='windrose_end_hour')

def get_windrose_figure_temp(st_month: int, st_day: int, st_hour: int, end_month: int,
                    end_day: int, end_hour: int, _epw, global_colorset) -> Figure:

    """Create windrose figure.
    Args:
        st_month: A number representing the start month.
        st_day: A number representing the start day.
        st_hour: A number representing the start hour.
        end_month: A number representing the end month.
        end_day: A number representing the end day.
        end_hour: A number representing the end hour.
        epw: An EPW object.
        global_colorset: A string representing the name of a Colorset.
    Returns:
        A plotly figure.
    """

    lb_ap = AnalysisPeriod(st_month, st_day, st_hour, end_month, end_day, end_hour)        

    fields = get_fields()

    windrose_data = _epw.import_data_by_field(fields['Dry Bulb Temperature'])

    wind_dir = _epw.wind_direction.filter_by_analysis_period(lb_ap)
    windrose_dbt_ = windrose_data.filter_by_analysis_period(lb_ap)

    lb_lp = LegendParameters(colors=global_colorset, max = 60)

    lb_windrose_temp = WindRose(wind_dir,windrose_dbt_)
    lb_windrose_temp.legend_parameters = lb_lp

    return lb_windrose_temp.plot(title='Wind Direction vs. Dry Bulb Temperature',
                                 show_title=True)

windrose_figure_temp = get_windrose_figure_temp(windrose_st_month, windrose_st_day,
                                                windrose_st_hour, windrose_end_month,
                                              windrose_end_day, windrose_end_hour,
                                              global_epw, global_colorset)

st.plotly_chart(windrose_figure_temp, use_container_width=True,
                config=get_figure_config(f'Windrose_{global_epw.location.city}'))

```

---

<div class="post-metadata">

**Author:** ![devang](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/devang/32/9082_2.png) [@devang](https://discourse.pollination.solutions/u/devang)\
**Post date:** [January 23, 2024, 2:03am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/6 "2024-01-23T02:03:35Z")

</div>

I understand what you are trying to achieve here. I am sorry to report that, we have not added the capability to load other data on top of Windrose chart yet.

---

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [January 23, 2024, 3:11am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/7 "2024-01-23T03:11:50Z")

</div>

Sorry @devang - I have a very messy script which I might have missed some of the functions but yes, you’re re right the basis is the one you provided before -

To make it clearer, the issue is not about the Windrose itself, it’s about the LegendParameters minimum and maximum values - I can plot DBT on top of Windrose and it works in C - but when I change the units to F, I have to adjust the min/max values accordingly for LP which doesnt work -

below is based on C unit which works fine -

![image](https://discourse.pollination.cloud/uploads/default/original/2X/7/7239eb90d54b8adf52688afc918938ab01ad56ef.png)

or maybe this is sth that is not related to ladybug\_charts, and @chriswmackey might be able to help as it sits under ladybug core module - not too sure -

---

<div class="post-metadata">

**Author:** ![devang](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/devang/32/9082_2.png) [@devang](https://discourse.pollination.solutions/u/devang)\
**Post date:** [January 23, 2024, 3:28am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/8 "2024-01-23T03:28:42Z")

</div>

This is a limitation of ladybug-charts. I will look into this.

---

<div class="post-metadata">

**Author:** ![devang](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/devang/32/9082_2.png) [@devang](https://discourse.pollination.solutions/u/devang)\
**Post date:** [January 25, 2024, 1:29am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/9 "2024-01-25T01:29:49Z")

</div>

Assigned @devang on January 25, 2024, 1:29am UTC



---

<div class="post-metadata">

**Author:** ![devang](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/devang/32/9082_2.png) [@devang](https://discourse.pollination.solutions/u/devang)\
**Post date:** [February 4, 2024, 7:44pm UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/10 "2024-02-04T19:44:47Z")

</div>

Pushed a fix. Will share once merged. Thank you for your patience.

---

<div class="post-metadata">

**Author:** ![devang](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/devang/32/9082_2.png) [@devang](https://discourse.pollination.solutions/u/devang)\
**Post date:** [February 4, 2024, 8:15pm UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/11 "2024-02-04T20:15:12Z")

</div>

Try with version 1.19.3

---

<div class="post-metadata">

**Author:** ![devang](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/devang/32/9082_2.png) [@devang](https://discourse.pollination.solutions/u/devang)\
**Post date:** [February 5, 2024, 12:08pm UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/12 "2024-02-05T12:08:58Z")

</div>

Unassigned @devang on February 5, 2024, 12:08pm UTC



---

<div class="post-metadata">

**Author:** ![amirtabadkani](https://discourse.pollination.solutions/user_avatar/discourse.pollination.solutions/amirtabadkani/32/5968_2.png) [@amirtabadkani](https://discourse.pollination.solutions/u/amirtabadkani)\
**Post date:** [February 6, 2024, 1:00am UTC](https://discourse.pollination.solutions/t/windrose-legend-issue/3525/13 "2024-02-06T01:00:40Z")

</div>

it works perfectly fine now - thanks a lot @devang
