I am trying to plot chart in my data science project. And I want to plot chart in this way
which is produced by Matplotlib library. And now I want to plot in the same way. But it gives me this way in bokeh.
My data for this in the form of python list and it is as below:
ages = [45.0,50.0,55.0,40.0,60.0,35.0,65.0,30.0,70.0,25.0,75.0,20.0,80.0,85.0,15.0,90.0,10.0,0.0]
ageCounter = [4466,4270,3824,3576,3240,2850,2527,2358,1968,1544,981,655,419,149,132,80,17,2]
Is there any thing I am missing.
Thanks in advance.
You need to sort the arrays together by age. Bokeh plots the points in the order you pass them in. The data above is out of order which explains the "zigzag".
Related
I am trying to plot 2D bars in a Plotly 3D figure. I understand that Plotly's 3D figures do not yet support bar charts out of the box, but I have come across some examples from other people on the Plotly forums which have shown how this might be achieved.
Please see the post Adding a shape to a 3D plot. This is close to what I am trying to achieve, but I am not trying to plot a histogram.
It appears plotting traces as a mesh3d, adding in the missing points and triangulating is the way to go for Plotly's 3D chart, according to other examples I have seen. Below is an example of what I am looking for that I created using Matplotlib.
As you can see, x axis is the date, y axis is the trace name and z axis is the value. I would like to see if I can achieve something similar using Plotly's 3D charts, which are so much better of course because of the client side interactivity.
Is there a working example for what I'm trying to achieve? I am simply looking to plot simple (date, value) per trace as 2D bars in the 3D figure.
There isn't any current way to have a bar chart in 3D with Plotly (at least that I am aware of).
Documentation: Plotly Python Open Source Graphing Library 3D Charts
As shown in the documentation, there aren’t any options for a bar chart. There are, however, alternatives like a bubble chart.
I am trying to create a grouped, stacked bar chart. I was able to do it in excel and this image shows what I am trying to create but I want to do it through Python. I have all the data in a pandas data frame that is able to create separate stacked bar charts but I cannot get the grouping as seen in excel.
Excel Formatting:
If you could do it in Excel with easy then I strongly suggest you to do it with Excel. Unless you have other requirements.
There are many libraries you can use to create this type of plot: matplotlib, seaborn, or plotly. The one I use most is plotly. You can see the list of sample figures of plotly here: https://plotly.com/python/
Or you can join plotly community, there are many pros there might help with figure. I find there is few pros on figures in stackoverflow to plotly community: https://community.plotly.com/
I come across this issue constantly; and my current solution is to create additional dataframes, I feel like there must be an easier solution.
Here is an example of data where I have multiple countries with multiple attributes:
If I wanted to plot Population vs. Depression (%) I would write:
ax = df.plot.scatter(x='Population', y='Depression (%)')
This isn't super helpful, as there are clearly lines linked to specific Countries (df['Country']). Is there a simple way to plot a scatter plot with different series (colors/shapes/etc) as different Countries?
Right now I use groupby to separate out individual Countries and plot them on the same axes (ax = ax).
Any thoughts or input would be greatly appreciated! Thank you!
Try c="Country" and then if you want some nice colors you can go colormap='viridis' for example documentation
ax2 = df.plot.scatter(x='length',
y='width',
c='species',
colormap='viridis')
Since you are using strings as variables we can't use this approach directly and need to convert the data to numbers. This can be done by writing:
c=df.country.astype("category").cat.codes
I have a set of data held in a dataframe, with another dataframe with the associated errors. I would want to plot this with seaborn, but I can't seem to find a way to do this. I can get a scatterplot, but not with errorbars.
I would want something like This
Which was produced with Matplotlib. Although if I can't plot the lines that is ok as well. I am able to get a basic scatterplot with the sns.scatterplot() method, but can't find any way to add the errorbars to it. Does anyone know how to do this in seaborn?
Thanks
I'd like to create a Bokeh vertical bar chart (vbar) coupled with a scatter plot. I need to start from a given ColumnDataSource (then filtered with a CDSView), as this is only a part of a complex visualization and I need all the plots to be linked together.
The only tricky part for which I didn't find anything about after extensive research is: how to show counts (i.e., the values provided in the top parameter of vbar) based only on data points that are both filtered AND selected in the scatter plot? Both the plots receive the same filters from which a view is created.
The documentation shows how to link selected points in different plots (by using the same ColumnDataSource object), how to filter them, and how to use vbar, but not all of them together.
Any hint? Thank you very much in advance.