This question already has answers here:
Plotting different colors in matplotlib [duplicate]
(3 answers)
Closed 5 years ago.
I have a pretty short python program to map my RAM usage over time.
while i < 1000000000000:
x.append(i);
y.append(psutil.virtual_memory().used);
plt.plot(x,y)
i+=1;
plt.show()
plt.pause(0.0001)
For some reason, this graph changes color every time a new data point is added.
Does this have anything to do with the plt.ion() I have? It also re-opens every time I close it. Do you guys have any solutions? Thanks in advance!
I figured it out!
The color (my primary problem) I could fix by adding a color="black" to the plt.plot() line. My code looked like this:
plt.plot(x,y,color="black")
I wasn't able to figure out the thing where it doesn't close, but that's okay, I can still close it from the task manager.
Related
This question already has answers here:
Matplotlib: How to plot images instead of points?
(2 answers)
How to insert a UTF-8 character onto an image
(1 answer)
Placing Custom Images in a Plot Window--as custom data markers or to annotate those markers
(5 answers)
How to make a tkinter canvas background transparent?
(2 answers)
Closed last month.
I wanted to make a chess game in python, but then I saw that you can do a lot of amazing things in matplotlib in terms of designing. I know that this is probably not the best way of doing this but I want to try this. Here is my main question.
How to scale and position images in matplotlib and tell me a bit more about it if possible?
This is what I have at this point:
import matplotlib.pyplot as plt
im = plt.imread('C:\\...\\bb.png')
imgplot = plt.imshow(im)
plt.show()
This just displays the image, I cant realy scale it nor position it.
I also found something like this, it displays the image in the right corner but I can't change anything or it just disappears or nothing happens... In short only misery.
newax = fig.add_axes([0.6,0.8,0.2,0.2], anchor='NE', zorder=1,)
newax.imshow(im)
newax.axis('off') #If I remove this there is a frame
Please help me out.
This question already has answers here:
How do I change the figure size with subplots?
(6 answers)
Matplotlib different size subplots
(6 answers)
Closed 2 years ago.
I would like to change the size of a graph (with multiple plots) in python to make it larger. using 'plt.figure(figsize=(6,3))' for example makes a new graph of a different size but its empty with just the axes, the actual plots do not show. can someone help me understand where i am going wrong? i have attached an image of my code in this question. thank you in advance enter image description here
Always write the plt.figure(figsize=(x,y)) before the line of code that will create the plot and end it by plt.show()
This question already has answers here:
How to adjust padding with cutoff or overlapping labels
(8 answers)
Closed 4 years ago.
So I'm using yellowbrick in Python, which is basically matplotlib and scikit-learn combined, to visualize some data.
My chart looks like this:
The labels get cut off. What I want to do is to adjust the figure so the labels on the right don't get cut off. I tried
plt.rcParams['figure.figsize'] = (10, 5)
plt.rcParams['font.size'] = 12
but when I rendered the figure, it's still cut off. Even when I save it as a png file it's still cut off. What am I missing here?
tight_layout method should solve your problem.
Generally you can use it with:
fig.tight_layout() # if fig is your figure handle
or
plt.tight_layout() # if stated within the context of your figure
This line of code should be added after the last plotting statement just before rendering the figure.
If this does not work, please post a fully working minimal code example, as described in mcve. Afterwards I'll be able to post a fully working solution for most, if not all, cases.
This question already has answers here:
How to remove gaps between subplots in matplotlib
(6 answers)
Closed 5 years ago.
I am attempting to plot a graph similar to the one attached below. The y-axis should be aligned and the x-axis scale and name should be same. Also, I want the dotted line as shown in the figure.
I tried combining two different graphs but that is certainly not a good way to solve this.
Sorry for the poor quality picture but the important points are mentioned.
Look into the matplotlib docs. I think you might be looking to use plt.subplots with the sharex argument.
This question already has an answer here:
Matplotlib: re-open a closed figure? [duplicate]
(1 answer)
Closed 5 years ago.
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure()
axe = fig.add_subplot(111)
axe.plot(x,y,'b-')
axe.plot(z,h,'r-')
Now, I can see 2 lines (blue and red) plotted on figure. But I accidentally close that figure window.
when I issue command fig.show(), or fig.draw(), the figure will never show up again. How can I bring up my original figure without executing above commands again?
Thanks in advance.
I ran your code but I'm not getting the output you described. "2 lines (blue and red) plotted on figure"
Closing the figure via gui destroys the gui toolkit, however, the figure object still exists, you can save it with fig.savefig(). I think the best approach would be re-creating the figure.
Hopefully this helps: Matplotlib: how to show a figure that has been closed.