0

I have a few questions about Matplotlib.

How I could get a circle's fill color to be of RGB value (0-255)? I can't seem to find any way to get the circle to take an int between 0-255 for an RGB value, only a float between 0-1.

How do I get matplot to take parameters from an optional file input, otherwise default to defaults in the program?

Can I get rid of the axis limits completely when plotting shapes, so that my shapes don't get clipped by either axis?

import numpy as py
import matplotlib.pyplot as plt
import random
from matplotlib.patches import Circle

//set default value for rgb values for a circle
R = random.nextint(0,255)
G = random.nextint(0,255)
B = random.nextint(0,255)


//check to see if there is a file that will override the default value 
for rgb value - this is one thing that I need help with



circle1 = plt.Circle((0.5, 0.5), 0.3, color=(0.7,0.9,0.1))
circle2 = plt.Circle((0.2, 0.3), 0.3, color=(0.3,0.2,0.4))
//this is what I would like to happen
circle3 = plt.Circle((0.2, 0.3), 0.3, color=(R,G,B)) - another thing that I need help with

fig, ax = plt.subplots() 

ax.add_artist(circle1)
ax.add_artist(circle2)

plt.axis('off')
plt.savefig("output.png")
plt.show()

1 Answer 1

1

To get a valid matplotlib RGB color array from a tuple of RGB values in the range between 0 and 255 you may simply divide by 255.

color = np.array((R,G,B)) / 255.

To get a figure without axes that clip the artist you may pin the axes to the edge of the figure

fig, ax = plt.subplots()
fig.subplots_adjust(0,0,1,1)
ax.axis("off")

To read in a file you may use open

with open("filename", "rb") as f
    content = f.readlines()

depending on the format of the file you may use numpy instead to directly get the numbers into an array,

arr = np.loadtxt("filename")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.