Last weeks thread here

Welcome to this week’s casual kōrero thread!

This post will be pinned in this community so you can always find it, and will stay for about a week until replaced by the next one.

It’s for talking about anything that might not justify a full post. For example:

  • Something interesting that happened to you
  • Something humourous that happened to you
  • Something frustrating that happened to you
  • A quick question
  • A request for recommendations
  • Pictures of your pet
  • A picture of a cloud that kind of looks like an elephant
  • Anything else, there are no rules (except the rule)

So how’s it going?

  • absGeekNZ@lemmy.nz
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    4 days ago

    You could do this with python and a couple of libraries. This is just an example, but you could import the data from a DB or use a CSV file.

    import matplotlib.pyplot as plt
    import numpy as np
    
    # Pie chart data
    labels = ['Category A', 'Category B', 'Category C', 'Category D', 'Category E']
    sizes = [30, 25, 20, 15, 10]
    colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99','#c2c2f0']
    
    # Pie chart
    plt.figure(figsize=(8, 8))
    plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', startangle=140)
    plt.title('Sample Pie Chart')
    plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
    plt.show()
    
    # Histogram data
    data = np.random.normal(0, 1, 1000) # Generate 1000 random data points with a normal distribution
    
    # Histogram
    plt.figure(figsize=(10, 6))
    plt.hist(data, bins=30, color='#66b3ff', edgecolor='black')
    plt.title('Sample Histogram')
    plt.xlabel('Value')
    plt.ylabel('Frequency')
    plt.show()
    

    • Dave@lemmy.nzOPM
      link
      fedilink
      arrow-up
      2
      ·
      3 days ago

      Ooh thanks! I’ll definitely have a play with this. What’s the step before this? Is it as simple as installing python, putting the code in somefile.py, then running it?

      • absGeekNZ@lemmy.nz
        link
        fedilink
        English
        arrow-up
        3
        ·
        edit-2
        3 days ago

        Yep, if you are running any type of Linux python is already installed.

        I always have a path in my python files to allow for direct running rather than calling python first. This only works on Linux.

        If you put
        #!/usr/bin/env python3
        as the very first line, you can make the file executable and it will just run

        otherwise you will have to call python first, e.g. python yourFile.py

        • Dave@lemmy.nzOPM
          link
          fedilink
          arrow-up
          1
          ·
          3 days ago

          Awesome, thanks! I’ll have a play with this over the weekend.