In Matplotlib the legend function has a keyword argument called fancybox that makes the legend slightly transparent to see the lines behind the legend. Here is an example function call:
import matplotlib.pyplot as plt
plt.legend(fontsize='xx-small', loc='best', fancybox=True)
I can't find anything similar to this in Bokeh. Does anyone know if Bokeh has the functionality to make a plot transparent without going behind the scenes and monkey patching something in for it? Thanks.
I'm using bokeh 1.0.2 and the following worked for me:
# Make legend fully transparent
plot.legend.background_fill_alpha = 0.0
Judging by this one example in the documentation, I think you can change the legend transparency setting the plot.legend.border_line_alpha, which changes the transparency of the border line and also the legend itself, apparently.
http://docs.bokeh.org/en/latest/docs/user_guide/styling.html#id2
(As of Bokeh 0.9.2) Configuring the legend background was only just added a few weeks ago in a recent PR. It will be in the upcoming 0.9.3 release at the end of August 2015.
A final note, Just FYO: due to the cross-language nature of Bokeh, the capability to style the background is a feature and function of the client JS library, BokehJS. There's currently no amount of monkey patching from the python side that have any effect on making something that is not possible in BokehJS be possible. We are working on making BokehJS extensible from python, however.
Related
all
Is there any chance I can use the math mode (latex code) in Bokeh? I checked all the Bokeh git issues (and possible options to solve) but nothing seems to work in my case :frowning:
Let’s say I have $\alpha_\beta$ (so alpha_beta) in my dataset (.csv) and I want to include it in a plot or hover - how would I do that? Sure I can use alpha symbol but how would I make beta be a subscript of alpha?
Thank you in advance!
Bokeh 2.4 adds support for LaTeX (and MathML) to some elements in Bokeh. Currently, you can use LaTeX on axis labels, tick labels, div widgets, and paragraph widgets. Unfortunately, LaTeX on hover labels is not yet supported, but LaTeX support for more elements should be added soon. For more information about the new math text feature and how to use them, see the Bokeh 2.4 release blogpost, the new blackbody radiation example, and the Bokeh user guide!
First time here and newbie so please bear with me.
I'm following along a data viz tutorial with matplotlib. I'm getting the same results (go me) but the font used (in the plot legend in particular) and the default co lours are different and no parameter has been set to change them. And of course the tutorial's stuff looks much nicer. I don't know why this happens but I'm thinking that maybe I did change some of the stuff in unrelated notebooks and those choices stuck. If so, how do I "reset" please?
I am not allowed to attach screenshots yet. Basically, my plot lines are light blue and orange while his are the traditional discrete dark blue and green. My legend font looks like bad excel while his looks like LateX.
Thank you for your suggestions.
There are a number of ways you can do this and they vary depending on the specific use case but the one I use most often is
from matplotlib import rcParams, rcParamsDefault
rcParams.update(rcParamsDefault)
Although it is likely the case that the tutorial is using a style other than the default so I wouldn't necessarily expect this to make your output look exactly like the tutorial. When using LaTex with matplotlib I use
pgf_with_latex = {
"text.usetex": True,
"pgf.rcfonts": False,
"pgf.preamble": [
r'\usepackage{color}'
]
}
rcParams.update(pgf_with_latex)
You can find more information here regarding customization and here regarding using LaTex with matplotlib.
To find all the built in matplotlib themes, use
plt.style.available
I think the normal one is 'default'. So add this before you make your plots:
plt.style.use(['default'])
But you can make your plots look even better than the tutorial by using some of the other ones.
How do I change the background color of the sides of a matplotlib inline plot in LightTable? In the image below, it's a little difficult to see the axis labels. I'm fine with either a python-based solution (i.e. modification of the python code shown), or a LightTable-based solution (i.e. a change in one of the settings files, but I'm not sure which one--e.g. is it user.behaviors?).
If you create a figure first, you can set the background colour using patch.set_facecolor:
fig=plt.figure()
fig.patch.set_facecolor('white')
Not sure if that works in LightTable (never used it before), but that does work in an ipython session so hopefully its portable to LightTable
I'm using tripcolor from matplotlib.pyplot to generate color plots of some data. The plot works great, but I'd like to turn off the edges which are drawn between data points:
subtle but pretty noticeable if you zoom in. I tried to get rid of them via:
plt.tripcolor(1e4*data_z, data_phi, data_I/1e3, shading='flat', edgecolors='none')
but the edgecolors='none' keyword arg seems to have no effect. I can, however, change the color from white to something else. Is there a way to get rid of them altogether?
I tried with an example from the official documentation, and the property edgecolor seems working well.
This is the result with edgecolors='w':
And this with edgecolors='none':
I am using WinPython 3.3.5 (with Matplotlib 1.3.1) under Windows 7, maybe you have a different version?
Take this page, for example, a sample of which is posted below:
It has matplotlib examples with gray background and more subtle coloring, but when I'm running the same examples, I get the more traditionally colored plots with white background and strong colors. This also seems to be the style used in the pandas documentation.
How can I change the default style locally to match their style?
If you read through the page you linked, just above the Plotting in Pandas section is the following line:
If you want to make your plots look pretty like mine, steal the matplotlibrc file from Huy Nguyen.
In the post is a link to this gist, which contains the matplotlibrc file. Make sure you read through the whole thing and customize it, as for example he has MacOSX as his backend, which you may want to change.
To use the file, save it as ~/.matplotlib/matplotlibrc and restart any running instances of IPython. Your plots should now look prettier :)
As MattDMo mentioned, using a sane matplotlibrc really helps.
The book "Probabilistic-Programming-and-Bayesian-Methods-for-Hackers" also uses a nice matplotlibrc. See this for some examples.
Recently I'm using the package seaborn instead of a custom matplotlibrc not only because it makes my plots look great, but also because it adds some functionality for visualizing distributions, linear models and time series.