
# the plot for the figure subtitle to go above the plot title! Use `top=0.8` to bring the top of the plot down to leave some space above # configure your figure title, subtitle, and footer.

When all done adding as many subplots as you want to for your figure, Plt.plot(x_vals, y_vals, 'r-o', label="Drag curve for Vehicle 1") Summary of other plot features and titles: # Figure title (super-title)įig.suptitle("Figure title", fontsize=16)įig.text(0.5, 0.015, "Figure footer: see my website at horizontalalignment="center") We use horizontalalignment="center" to ensure it stays centered left and right. The 0.9 y-location puts it a little down from the top, so that it will end up under the Figure title. The 0.5 x-location is the halfway point between the left and the right.
#Pyqt4 matplotlib annotate how to#
Here's how to do a subtitle: just use a regular figure text box stuck in the right place: # Figure subtitleįig.text(0.5, 0.9, "Figure subtitle", horizontalalignment="center") It's pretty thorough, for all your title and label needs. But now I notice this was not the case and the GUI seems to work as intended.Here's a hello world I wrote as I was figuring out how to use matplotlib for my needs. I don't recall why now, but I assumed that simple calling () would stack up old plots and I would have to clear the figure first. The second solution is, however, my preferred because it does not involve duplicating objects. The reason the first solution above works is because when deepcoping an object, we decouple from new_figure, and then can perform.
#Pyqt4 matplotlib annotate update#
Then, when I was trying to update the canvas with a new_figure, the methods () and () were acting upon the same object as referred by new_figure, virtually erasing its data. My original problem is that I did not notice that when I was passing new_figure to the function update_figure, and "assigning" it to, what I was really doing was making refer to the same object. This appears (up until now in my tests) to allow the canvas to be refreshed. This appears to take some time to update the figure Use the copy module and the deepcopy method to copy the new_figure object into.

In case anyone come across this post, I have devised two alternatives to deal with this problem: I tried to see if there would be some way to copy the entire information of the figure object and inserted in the current axis of the canvas, but had no luck with that. # Copy the contents of the new figure onto the canvas

# new_figure is a matplotlib figure object #Get the default font style from the system and apply to the canvas Self.canvas = FigureCanvasQTAgg(Figure()) In both methods, the variable "new_figure" is a matplotlib figure object. Then, the method "add_figure" would be used to plot the subsequent figure objects. The method "update_figure" is used to plot the first figure object to the canvas (and it is already working). Here is a minimum working example of the matplotlib widget I have. Now, I am struggling to discover how can I (or even if it is possible) to plot a figure object in the same matplotlib canvas that a previous figure object has been plotted, without erasing the previous plot. The graphs to be visualized are entirely built inside functions that return an already assembled and ready to be plotted matplotlib's figure object - in this case, a object not natively managed by pyplot (and I preferrable wouldn't change this). I am building a GUI with PyQt6 which has a part for graph visualization based on matplotlib.
