Update figure without saving - python

Using the PGF-backend for matplotlib, I am trying to modify the ticklabels of my logarithmic y-axis. I do not however know beforehand what my ticklabels will be, so I'd like to get the ticklabels with ax.get_yticklabels() and then modify the text of the labels (by removing a substring). The problem is, that the list returned by get_yticklabels() is only filled when issuing the savefig('plot.pdf') command.
Is there a function that updates the whole figure without actually saving it, so I can get to the labels? The fig.canvas.draw() function does not work as I would have expected. I am using matplotlib version 1.2.0 with Python 3.3.0 on Linux.
PS: The underlying problem is, that I can't get a sans-serif font for the labels on logarithmic plots with the PGF-backend, which I am pretty sure is a bug in the backend. Any solution to that would of course also be welcome and make my initial question obsolete.

Related

How to Mix Markers and Labels in Matplotlib Legend

I am working on a figure where space is constrained and I want to combine my legend using parentheticals as in this picture.
At the moment I just make some parenthesis in my labels for the plot and then edit the figure in Inkscape later on to add the missing markers, but this makes iterating on the plot more expensive in terms of time before having a usable figure. Is there any way to hack matplotlib into doing something similar without having to go through an external program?

python bokeh saving issue and label disappear, and display problem

As I am aiming to plot the data into the plot, I encounter 2 problems.
(1) For the Bokeh function, while I am plotting 4 pictures in a row and adding the save as the SVG. Then the browser is shown as figure1. Moreover, as I comment out the code below, it work definitely right as I thought. It's weird.
p1.output_backend = "svg"
export_svgs(p1, filename="./number_like_comment/fig/{}.svg".format(action_str))
(2) For the second question, after I save those files, I realized that the "Label" I put in the plot also disappear. (as figure3).
Thanks so much for reading through. This question bother me quite a long time.
I guess that the data (on the x-axis) starts at 0, and on a logaxis for some reason the svg renderer doesn't like that and refuses to draw the entire line. The canvas renderer (used for the interactive plots) only refuses to draw the line-segment going from or to 0.
If you want to keep the logarithmic axis, you can either remove the 0 values or replace them by something which can be displayed in a logarithmic scale (e.g. 0.1) and then fixate the x-axis.

Using matplotlib when one should use `axes`?

Let me first say I've never studied matplotlib and pyplot organically. I've been able to employ these fantastic tools to some success however without developing a big picture of how things are supposed to be used. One of the thing that confuse me the most is the use of axes instances.
In many occasions I have found solutions to a particular problem which make use of axes or do not.
Example: one can set ticks to the x-axis through matplotlib.pyplot.xticks without using axes or through matplotlib.axes.Axes.set_xticks.
I usually try to avoid the use of axes. However there are times at which this seems to not be possible. For example when trying to use subplots with shared axis.
Can someone help me to shed some light on this subject? When am i supposed to use axes? When should I not?
Thanks.

How to save matplotlib figure in max windows form instead of default size?

Anyone know how should i work around with that?
I know there is save button which I could do it manually but I am plotting 100+ graph so I hope there will be a way to doing it automatically?
I was using 'TkAgg' backend and I look up for any possible solution around. By using the following at the end of my plot function.
manager = plt.get_current_fig_manager()
manager.resize(*manager.window.maxsize())
plt.savefig(r'C:\Users\310293649\Desktop\PlotFigure\TESTING.png')
plt.show()
EDIT: Tried with this as well but still I was able to plt.show() the figure in the desired way I prefer which is full windows size. But it still automatically save all of my figure in minimize default form.
wm = plt.get_current_fig_manager()
wm.window.state('zoomed')
plt.savefig(r'C:\Users\310293649\Desktop\PlotFigure\TESTING.png')
plt.show()
Below is what I got after plt.show() from above command,
plt.savefig result that I got:
As you can see The code managed to show the plot in max windows size but it still automatically saved the plot with default size So I was wondering if it is possible or is there any solution to save the matplotlib figure in max windows size automatically? OR there is no way I can do that?
Below images is the figure when I done it manually with the save figure button in matplotlib:
EDIT: How to make pylab.savefig() save image for 'maximized' window instead of default size - Most of the answer here refer to showing the figure in full windows form but when it come to saving the max windows automatically(it still save it in the normal size)...you can see the author of the ques have raised up the issue in the comment section of all of the answer but was not answered.
Apparently, this is a bug introduced in Matplotlib 2.0 (January '17).
See here and here.
There seems to be a fairly simple code change to fix this here, but you'll have to apply it yourself since it's not included in any released version yet (it's planned for 2.1.1 2.2).

How to remove renderers from a plot?

I'm experimenting with Bokeh server. I have a document with three figures and I'm trying to update two of them depending on the selection I perform on the third. The number of lines to plot in the two figures changes every time.
If I could use multi_line, this would be trivial: I would change the xs and ys in the data_source of the multi_line.
Alas, I need to use multiple scatter plots because multi_line does not support hover and I need it.
So, what I would like to accomplish is to clear the two plots every time I select something in the third, and display the scatter plots corresponding to the new selection.
There are a few possible workarounds, of course (appending scatter points to have a single GlyphRenderer with all scatter plots together, for example, but this would mean using very clunky ways to send the right hover message...). But if it was possible to just clear and update single figures, everything would be cleaner. I couldn't find anything in the docs, however.
I have read the thread you created on the mailing list and this other thread where Bryan says:
Technically, glyph renderers are stored in the .renderers property of
Plots, but I would not recommend rooting around there by hand.
Specifically the "Continuous Updating" notebook I linked earlier has
an example of updating both the data and appearance of an existing
glyph using python and push_notebook. There is not any easy way to remove glyphs at the moment,
other options would be:
recreate a new plot
set the glyph to be invisble
update the glyphs data
So it seems they are the only solutions at the moment

Categories

Resources