How to plot multiple stacked x-axis boxplot using Plotly Python - python

I wish to create multiple stacked x-axis using plotly python with below code. However, it only allows me to stack up 2 levels. Need Help. Thank you.
img1 = go.Figure()
img1.add_trace(go.Box(x=[df1['A'], df1['B'], df1['C']], y=df1['y_value']))
What I get:
What I want:

Related

Creating a plotly vrect over all axis of a matplotlib plot

I have a complete matplotlib figure with multiple subplots and I want to add a vertical span in a specific range to all of the subplots. The remaining plot is then converted to plotly.
If I try running xvspan over each individual subplot when creating the matplotlib figure, the vertical spans do not make it into the plotly figure.
If I try converting the figure into plotly first and then adding a vrect, this vrect only seems to work for the first subplot. I have tried using row = "all" to no avail.
Any other ideas?
Thanks!

Plotting pandas vs matplotlib

For a little jupyter notebook widget i tried the following:
with output:
fig, ax = plt.subplots(constrained_layout=True, figsize=(6, 4))
# move the toolbar to the bottom
fig.canvas.toolbar_position = 'bottom'
ax.grid(True)
line, = ax.plot(df.index, init_data, initial_color,)
ax.set_ylabel('CH4_HYD1')
ax.set_ylabel('')
But the data gets plotted in a wierd way. When isolating the plotting method and comparing it to the pandas default, the pandas plot displays the data correctly.
df['CH4_HYD1'].plot()
Pandas plot
plt.plot(['CH4_HYD1'])
Wrong plot?
I would like to use the axis plot method to produce a plot with multiple lines of different features. But I can't find the probably very simple error... What is the difference here?
This is a short example of how to plot multiple lines from a DataFrame with matplotlib and with pandas. Essentially, pandas uses matplotlib to do the plots so it shouldn't be different.
Anyway, I encourage you to look into seaborn. This is a great library based on pandas and matplotlib that enables visualizing dataframes easily.

shared_xaxis with plotly, but can I still display the axis on each plot?

if you share the x_axis between 2 plots, they will get aligned, as expected.
however, the axis is displayed only once, on a single plot and not on both anymore.
Is it possible to display the axis on each plot?
If you're using Plotly Express, there is no way to do this at the moment. If you're using the underlying make_subplots method, however, this is the default behaviour: https://plot.ly/python/subplots/

How to create a Bar Chart with Python Pandas with Greek Labels

i am trying to make a bar chart using pandas and matplotlib. The data is depicted in the dataframe (champs_by_number_of_matches) bellow and it is Greek.
by typing: champs_by_number_of_matches.plot(kind = 'bar')
i get the graph bellow. How can i get the x-axis labels to show Greek?
This is a frequent problem i have encountered and i dont want to convert the labels to "Greeklish".
Thank you.

show two plot together in Matplotlib like show(fig1,fig2)

In general, I don't have any problem to put two plots in a figure like plot(a);plot(b) in matplotlib. Now I am using a particular library which would generate a figure and I want to overlay with boxplot. Both are generated by matplotlib. So I think it should be fine but I can only see one plot. Here is the code. I am using beeswarm and here is its ipython notebook. I can only plot beeswarm or boxplot but not both in a figure. My main goal is trying to save column scatter plot and boxplot together as a figure in pdf. Thanks,
from beeswarm import beeswarm
fig=plt.figure()
figure(figsize=(5,7))
ax1=plt.subplot(111)
fig.ylim=(0,11)
d2 = np.random.random_integers(10,size=100)
beeswarm(d2,col="red",method="swarm",ax=ax1,ylim=(0,11))
boxplot(d2)
The problem is with the positioning of the box plot. The default positioning list starts with 1 what shifts the plot to 1 and your beeswarm plot sits on 0.
So the plots are in different places of your canvas.
I modified your code a little bit and that seems to solve your problem.
from beeswarm import beeswarm
fig = plt.figure(figsize=(5,7))
ax1 = fig.add_subplot(111)
# Here you may want to use ax1.set_ylim(0,11) instead fig.ylim=(0,11)
ax1.set_ylim(0,11)
d2 = np.random.random_integers(10,size=100)
beeswarm(d2,col="red",method="swarm",ax=ax1,ylim=(0,11))
boxplot(d2,positions=[0])
Cheers

Categories

Resources