I am trying to get deep into hvplot to see if I can find a good alternative to plotly, but I am baffled by the documentation.
I am trying to plot boxplots with jittered points, and a basic tutorial can be found here.
The part of the example I am trying to customize is this:
import hvplot.pandas
from bokeh.sampledata.sprint import sprint as df
boxplot = df.hvplot.box(y='Time', by='Medal', height=400, width=400, legend=False)
boxplot
However, I want to style my plot, for example by removing the borders of each box, changing opacity, box width, and so on.
I tried to search that in the hvplot page, but the documentation seem to be limited to some basic examples and not much more.
On stackoverflow I managed to find some pointers to how to style plots but I tried and failed to find out how to do the above mentioned things.
Is there a more detailed documentation somewhere or do I just need to get deeper into holoviews?
Update:
I found in the customization guide of HvPlot that one can call hvplot.help('box'). That contains all the possibile options. The fact that box_color doesn't work still eludes me (box_fill_color works) but at least that's a more detailed explanation of how it works.
Leaving it here just in case someone else needs it.
Related
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.
I am trying to achieve a Boxplot with hover tool tip in Python
I have tried bokeh.charts and bkcharts which are deprecated and no module is found for the same.
I even tried mpld3, but all I got was Scatter plot with the tooltip,
I even tried the bokeh box plot https://docs.bokeh.org/en/latest/docs/gallery/boxplot.html from here but it is very complex and making use of unnecessary groupby column.
If anyone has boxplot with hover tool tip in python than please help.
Similar functionality can be achieved very easily in R so why not in Python???
did you try plotly?
This example may help.
You may have to add JS code so I'm aware this may not be what you need. Switch to tab "Python & R" and look at the Python code. There are comments there.
I'm just wondering if it exists an equivalent to the Matlab figure window in Python where we can modify plots directly from the figure window, or add some features (text, box , arrow, and so on), or make curve fitting, etc.
Matplotlib is good, but it is not as high-level as the Matlab figure. We need to code everything and if we want to modify plots, we need to modify the code directly (except for some basic stuffs like modifing the line color)
With matplotlib, you will indeed remain in the "code it all" workflow. This is not directly the answer you expect but the matplotlib documentation recently gained a very instructive figure that will probably help you if you stay with matplotlib: http://matplotlib.org/examples/showcase/anatomy.html shows the "anatomy" of the figure with all the proper designations for the parts of the figure.
Overall, I could always find examples of what I needed in their excellent gallery http://matplotlib.org/gallery.html
In my opinion, you'll save time by coding these customizations instead of doing them by hand. You may indeed feel otherwise but if not there is a ton of examples of matplotlib code on SO, in their docs and a large community of people around it :-)
Can't find a way of adding errorbars to a Python ggplot plot. The following issue has been neglected for over a year. Nothing in the docs.
I had this same problem and found no solution. However I did find a way around it. You can use matplotlib in the style of ggplot. From there it's much easier to use error bars. I've attached an example of some code I used.
plt.style.use('ggplot')
This is an extract of one of my codes
df2.gLongCrFiltered['mean'].plot(kind='bar', yerr=df2.gLongCrFiltered['std'])
which returned this
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.