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'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.
Altair offers lovely feature to facet charts using facet method. For example, following dataset visualizes nicely:
print(df[['Year', 'Profile', 'Saison', 'Pos']].to_csv())
,Year,Profile,Saison,Pos
0,2017,6.0,Sommer,VL
1,2017,6.0,Winter,VL
13,2017,6.0,Winter,HL
12,2017,6.0,Sommer,HL
18,2017,6.0,Sommer,HR
6,2017,6.0,Sommer,VR
7,2017,6.0,Winter,VR
19,2017,6.0,Winter,HR
14,2018,5.5,Winter,HL
8,2018,5.5,Winter,VR
15,2018,5.5,Sommer,HL
20,2018,4.3,Winter,HR
21,2018,5.0,Sommer,HR
3,2018,5.5,Sommer,VL
2,2018,6.2,Winter,VL
9,2018,4.5,Sommer,VR
17,2019,4.5,Sommer,HL
11,2019,4.2,Sommer,VR
22,2019,3.5,Winter,HR
10,2019,5.28,Winter,VR
5,2019,4.6,Sommer,VL
4,2019,4.9,Winter,VL
16,2019,4.0,Winter,HL
23,2019,4.5,Sommer,HR
with the following command:
alt.Chart(df).mark_bar().encode(x='Year:O', y='Profile:Q').facet(row='Saison:N', column='Pos:N')
But, as you can seem I have still a lot of place horizontally and would like to use it by rearranging Winter plot right next to the Summer plot:
I understand that I already used column grid to facet over attribute Pos, but visually for me Winter and Sommer plots are two separate plots (just like here), which I'd like to place side by side.
I tried to create two different charts in the same cell and using html emit them side by side, but in Jupyter environment there is a limitation on just one Altair/Vega plot per cell.
Is there any method I can use to arrange these charts horizontally?
In Altair, there is no good way to do this, because faceted charts cannot be nested according to the Vega-Lite schema. However, the Vega-Lite renderer actually does handle this in some cases, despite it technically being disallowed by the schema.
So you can hack it by doing something like this:
chart = alt.Chart(df).mark_bar().encode(
x='Year:O',
y='Profile:Q'
).facet('Saison:N')
spec = alt.FacetChart(
data=df,
spec=chart,
facet=alt.Facet('Pos:N')
).to_json(validate=False)
print(spec)
The resulting spec can be pasted by hand into http://vega.github.io/editor to reveal this (vega editor link):
You'll even notice that the vega editor flags parts of the spec as invalid. This is admittedly not the most satisfying answer, but it sort of works.
Hopefully in the future the Vega-Lite schema will add actual support for nested facets, so they can be used more directly from Altair.
I am doing a project that needs to create some piecharts with pyqtgraph library. I can make column charts and line charts using the pyqtgraph.GraphicsWindow,but I can't find out how to create a piechart. Are there some methods that can help me to accomplish that?
Another problem, I don't know how to change the x Axis scale by some discrete settings. For example, when I make a column chart, I want to set a number '5' to the first column, '7' to the second column,'16' to the third column.....how can I implement this?
For the first problem, pyqtgraph has no built-in pie chart graphics. However, these should be fairly simple to construct by creating one QGraphicsEllipseItem for each wedge.
For the second, use the following:
majorTickValues = [(0,"5"),(1,"7"),(2,"16")]
plotItem.getAxis('bottom').setTicks([majorTickValues])
I want to be able to nicely align the description and the plot of following configuration:
I want to achieve that every plot has the same size, i.e. they end all on the same imaginary vertical line. The channel names should be aligned. Currently, I'm using a QGridLayout. The plots were created using Qwt.