Skip to content

Automatic Percentage Formatting of Normed Axes #294

@needham-michael

Description

@needham-michael

Requesting a minor addition to include a %-sign on the y-axis values when the normed=True flag is used.

I believe this should be a simple fix and have provided a simple example below which relies on matplotlib.ticker.PercentFormatter.

Likely would just need to pass the normed=True kwarg to the WindAxesFactory create method. I would be willing to open a PR for this.

Minimal Working Example

import numpy as np
from matplotlib.ticker import PercentFormatter
from windrose import plot_windrose

df = pd.DataFrame(data={
    'speed':np.random.random(1000),
    'direction':np.random.randint(low=0,high=361,size=1000),
})

ax = plot_windrose(df,kind='bar',normed=True)

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
# Adding this line formats the y-axis as x%  #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
ax.yaxis.set_major_formatter(PercentFormatter())

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions