Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

is there a Python graph library that saves the graph as a image?

so I am making a discord bot and when you start it will generate your character with three traits.

async def PersonGenerator(ctx):
    athour = ctx.author.mention
    with open ("mainData.json", "r") as f:
        Stfu = json.load(f)
    if str(athour.id) in Stfu:
        Traits = ("Agile: +30 Attack Speed", "Ambitious: +2 Diplomacy, +4 Warfare, +1 Stewardship","Attractive: +2 Diplomacy, +1 Stewardship", "Blessed: +9 Damage, +15 Speed, +10% Dodge, + 1.5 times Health", "Content: +2 Diplomacy, +2 Stewardship", "Deceitful: +1 Diplomacy, +4 Stewardship", "Dragonslayer: +4% Critical Chance, +1 Diplomacy, +6 Warfare", "Eagle-Eyed: +15 Damage" , "Energized: May summon lightning on death", "Fast: +20% Base Speed, +5 Attack Speed", "Genius: +5 Diplomacy, +5 Warfare, +7 Stewardship", "Giant: +50% Base Health", "Honest: +2 Diplomacy, +3 Stewardship", "Kingslayer: +5 Attack Speed", "Lucky: +5% Dodge, +4% Accuracy", "Mageslayer: +4% Critical Chance", "Pacifist: +10 Diplomacy", "Pyromaniac: +3 Warfare", "Strong: +3 Damage, +5 Diplomacy", "Tough: +2% Armor", "Veteran: +3 Damage, +1% Armor, +3% Dodge, +1% Accuracy, +5 Diplomacy, +30 Health", "Weightless: Allows walking over Ice", "Wise: +5-10 Diplomacy" ,"Greedy: -2 Diplomacy, +4 Warfare", "Paranoid: -2 Diplocacy, +4 Warfare", "Tiny: -50 Health, +5 Speed", "Tall: -5 Speed, +50 Health")
        random_trait = random.choice(Traits)
        y = y + random_trait
        random_trait = random.choice(Traits)
        y = y + f", {random_trait}"
        random_trait = random.choice(Traits)
        y = y + f", and {random_trait}"
        await ctx.send(f"Wow! Here are your traits!\n{y}!")

but now I want it to generate a pie graph about your character, a bar graph about your character, and a line graph of how different your character is from the average character. but I need the graph to be generated as an image so I can send it through discord. does anyone know a graph library like the one I am requesting?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do just that with matplotlib

Here is an example using a list of made up stats

import matplotlib.pyplot as plt
stats = [2, 4, 7, 2, 4, 5, 2, 5, 1, 4]
plt.pie(stats);
plt.savefig('traits.png')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading