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

Question:

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?

Asked By: supper_grag_tag

||

Answers:

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')
Answered By: 1azza
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.