How to update an image without adding new colorbar every time - matplotlib

I am displaying an image with matplotlib. However, every time I update this image, a new colorbar is added to the right and my image is shrunk.
1st time running the code
2nd time running the code
3rd time running the code
4th time running the code
if slice1 is a 2D array
plt.figure("slice 1")
plt.imshow(slice1)
plt.colorbar()
plt.clim(0, 1000)
plt.set_cmap('gray')
plt.show()
I would like to have the colorbar and image stay at the same place every time I run these lines.

Related

Plotting Vertical Lines

I want to plot tomorrow's key times with vertical lines and want them plotted in advance of the time, not once the time comes.
I have used indicators that plot session times but they only plot the line after the time hits. I want them plotted before the actual time hits. I want tomorrow's key times to be visible today.

PyQt application issue with matplotlib bar graph x ticks

I'm making a application to show graph using python pyqt5 and matplotlib.
here is a issue with graph I don't know why this happen.
You can see the 2 graph image I uploaded.
Second one is what I want to show.
But after show pie graph(There are so many types of graph I used in my application but only after pie graph happen this issue), it work like first image.
So, I wrote code after draw pie graph
self.MplWidget.canvas.axes.clear() like this.
But it doesn't change at all.
If I reboot my application it work well.
How I can show my graph like image2 after show pie graph?
this is my code to show bar graph
self.MplWidget.canvas.axes.bar(ind, graph1, width, label='price1' )
self.MplWidget.canvas.axes.bar(ind, graph2, width, bottom=graph1, yerr=Std, label='price2')
self.MplWidget.canvas.axes.title.set_text('graph1')
self.MplWidget.canvas.axes.set_xticks(ind)
self.MplWidget.canvas.axes.set_xticklabels(temp['date'], rotation=90 )
self.MplWidget.canvas.axes.legend(loc='best')
self.MplWidget.canvas.draw()
this is my code to show pie chart
self.MplWidget.canvas.axes.title.set_text('pie graph')
self.MplWidget.canvas.axes.pie(sizes, labels=labels, autopct='%1.1f%%',shadow=True, startangle=90)
self.MplWidget.canvas.axes.axis('equal')
self.MplWidget.canvas.draw()
self.MplWidget.canvas.axes.clear()
Axes.pie sets the aspect ratio of the axes to 'equal' which is what seems to mess up the bar plot. You could try setting self.MplWidget.canvas.axes.set_aspect('auto') when plotting the bar plot to reset the aspect ratio to 'auto'. You probably also want to set self.MplWidget.canvas.axes.set_frame_on(True) since Axes.pie removes the frame around the plot as well.
Another option could be to use separate widgets for each of the plots and combine them in a QStackedWidget or QTabWidget.

How do I increase the the size of subplots in pair plot?

I've a dataset in which there are 15 different numeric columns and I would like to plot a pair plot using seaboard. However the image size of subplots is too small to make any inference from it.
I've tried using height and aspect with pair plot. However it doesn't seems to be working for me. The plot size keeps on reducing. The same goes for fig size.
plt.figure(figsize=(40,40))
sns.pairplot(df)
plt.show()
I'm expecting a a good enough size of all the pairs so that some inference can be made on the same. However I'm getting plots too small in size to even recognise the column name.
The command works for me.
I was not aware that in Jupyter notebook we can maximise the output to its actual size.
So essentially, below works just fine.
plt.figure(figsize=(100,100))
sns.pairplot(df)
plt.show()

core plot stacked graph crossing top border

I'm trying to create a stacked graph using core plot.i have followed this tutorial.I have a UISlider on sliding i'm updating my graph.The issue i'm facing is my top value for y-axis is touching top border(As in the screen shot). As per my requirement in need to round off the highest value to next 10th value so that my graph doesn't touch the borders.On changing my slider value the x and y axis should also get refresh,i'm doing it by regenerating plot but it takes a lot of memory.Any idea how can i achieve these requirement ?
Don't recreate the whole graph every time the values change. Call -reloadData on the graph to refresh the plot data and set the xRange and yRange of the plot space to change the scale of the axes.

Core Plot: Updating position of y axis

Im currently doing a real time plot where I generate data every second. The problem I'm running into is that after about 15 seconds or so, because of how I have my xRange set, my plot begins to move/scroll automatically, which is an intentional effect, however my y axis seems to be rooted at the origin and quickly falls off screen. How would I either set the position to be rooted at the center of the view constantly, or what property do I need to update in order for the Y axis to also move?
I've looked through them all but I don't see anything obvious, or anything that seems to apply based on the included definitions/help.
I happened to find the answer in an old google groups thread, so I will post it here as a confirmation of it working in Core Plot 1.0, and since this is a bit more organized/searchable place.
When you're initializing the plot, you want to set the axis constraint as follows.
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];