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?
Related
You would think this is Google-able but I haven't been able to find anything.
pandas' plot function uses matplotlib, so you can use the matplotlib functions set_xlabel and set_ylabel
plot = df.plot(x="Some Data",y="Other Data",kind="hist")
plot.set_xlabel("X")
plot.set_ylabel("Y")
I had likely issue with all labels missing from histogram and found very unusual cause of the problem
I use Dark Reader extension to put all notebooks in dark mode. This extension simply make plot's background black and all lables become invisible, because they are also black. Kind of silly, but I spend some time trying to solve this riddle
By default, matplotlib plot can place lines very inaccurately.
For example, see the placement of the left endpoint in the attached plot. There's at least a whole pixel of air that shouldn't be there. In fact I think the line center is 2 pixels off.
How to get matplotlib to draw accurately? I don't mind if there is some performance hit.
Inaccurately rendered line in matplotlib plot:
Inaccurately rendered line in matplotlib plot - detail magnified:
This was made with the default installations in Ubuntu 16.04 (Python 3), Jupyter notebook (similar result from command line).
Mathematica, for comparison, does subpixel-perfect rendering directly and by default:
Why can't we?
Consider the following to see what is going on
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 4], clip_on=False, lw=5, alpha=.5)
ax.set_xlim([1, 3])
fig.savefig('so.png', dpi=400)
You can also disable pixel snapping by passing snap=False to plot, however once you get down to placing ~ single pixel wide line, you are going to have issues because the underlying rasterization is too coarse.
The problem is even more notorious when one plots functions which are symmetric with respect to the x axis and slowly approach zero. As for example here:
which is indeed embarrassing if you are telling the reader of a scientific paper that the two curves are symmetric!
I went around this problem by exporting to pdf instead of exporting to png:
I completely agree that this should be worked on. I find that plt.plot gives (at least more or less) unshifted lines (in Jupyter) by calling plt.figure with dpi=144 (the default is 72). The figures do become twice as big though...
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.
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
when I use inline plots in iPython (QtConsole), the first plot looks (more or less) fine, but then it gets weirder and weirder. When I plot something several times (so plot, see it displayed, plot again, see output etc.), it looks like it is being overlaid with the skewed previous picture. So after plotting a diagonal line (x=y) 4 times in a row I get something like this
If i right click and export it as svg everything looks good
(Exported PNG picture remains wrecked as the first one).
I guess the problem is similar to https://github.com/ipython/ipython/issues/1866, but I didn't got the upshot of the discussion (it got too technical and complicated for me to follow).
Is there any solution or work around for this issue?
I'm using
python 2.7
matplotlib 1.4.1
IPython 2.1.0
Here is a working example:
%matplotlib inline
% config InlineBackend.figure_format = 'svg'
import matplotlib.pyplot as plt
a=range(10)
fig,ax=plt.subplots()
ax.plot(a,a)
ax.axis('off')
if you remove plt.axis('off') line, weird things happen only outside of the axis box.
P.S. Originally I encountered this problem in connection with drawing graphs with networkx. If I use draw from networkx this problem does not occur. If I use draw_networkx, same as described above happens. That might point to the core of the problem... I'm trying to figure out what line of code makes one work better than the other...
After tinkering around with the draw and draw_networkx functions from networkx module, I found the workaround which makes the difference between draw and draw_networkx in this case.
Adding fig.set_facecolor('w') overlays whatever is in the background, so the new plots are started with a white sheet (but not a blank one, I guess).
So new working example is:
%matplotlib inline
% config InlineBackend.figure_format = 'svg'
import matplotlib.pyplot as plt
a=range(10)
fig,ax=plt.subplots()
fig.set_facecolor('w')
ax.plot(a,a)
ax.axis('off')