Plotly figures in Jupyterlab with no horizontal scroll bar - python

If the plotly Figure is wider than the screen, I cannot see the right part because the horizontal scroll bar is not present.
I have something like this:
I looked for everywhere but it seems that no one had this problem before.
Any advices?
Thank you in advance
I also put the code here, as requested
import plotly.express as px
long_df = px.data.medals_long()
fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form Input")
fig.update_layout(width=1800, height=800)

Related

Hide coordinates in matplotlib

I am currently trying to hide the coordinates in a grid in matplotlib (see code below). Unfortunately no matter which way I try it only the bottom right position gets hidden. All other coordinates/axes are still being displayed. Would be wonderful if someone could help me with that since I do not know what else to try right now.
import matplotlib.pyplot as plt
from PIL import Image
fig,ax = plt.subplots(6,7)
plt.axis('off')
filenames=['gelb.png'.format(i) for i in range(42)]
for i in range(42):
#plt.axis('off')
with open(filenames[i],'rb') as f:
image=Image.open(f)
ax[i%6][i//6].imshow(image)
fig.show()

How to change the edgecolor of an Histogram in plotly?

I'm trying to change from matplotlib to plotly and I have to relearn every basic move.
One of my habit was to change the edge color of every histogram I made to white so it is easier to see the bars.
On matplotlib, I would do it like that :
import matplotlib.pyplot as plt
import numpy as np
vals = np.random.rand(50)
plt.hist(vals, edgecolor='white');
Which gives me :
I suppose there is a way to do it with plotly but I searched in the doc and other stackoverflow questions and haven't found it yet.
Closest way (that make me believe it is somehow possible): setting the template of the figure to a template using white edgecolor
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import numpy as np
vals = np.random.rand(50)
fig = px.histogram(x=vals, template="simple_white")
fig.show()
I also tried to examinate the template simple_white and to look for the param that was making the edges to be white but this didn't lead to anything (if you know what this param is, the answer interests me even more !)
There is function called fig.update_traces you can increase marker(edge) width and change color to 'White' like:
fig = px.histogram(x=vals)
fig.update_traces(marker_line_width=1,marker_line_color="white")
fig.show()
Reference: https://plotly.com/python/reference/histogram/
plotly.graph_objects.Histogram accepts a Marker as input argument. That means you can enable the borders and specify their color using a marker:
import plotly.graph_objects as go
fig.show()
go.Histogram(x=vals,
marker=dict(line=dict(width=0.8,
color="white")))
To see all other parameters of a marker, see the docs here.

plotly no space between pie chart and legend

I'm using plotly and I ahave created pue chart. the problem is that it works on jupyter ntoebook but when I download the graph the legend is overlap with the chart.
This is the plot on jupyter notebook:
but when I download it it as png it looks like this:
as you can see the legend items have very long names, but i'm not sure that cause the problem. Is there any way to control the spacing between the chart to the legend?
Edit: code sample:
import plotly.express as px
import plotly.graph_objects as go
fig = px.pie(df, values='count', names='LC', title='Land cover')
fig.update_layout(title_x=0.48)
fig.show()
I have also tried to play with the location of the legend this way:
fig.update_layout(title_x=0.48,legend={"x" : 1.7, "y" : 1})
but as I said, in jupyter notebook it worls but in the PNG is overlap just the same, even when X is equal to 3:

Animated multiseries Line Graph using Plotly Express (Python)

I am trying to animate a multi series line graph using plotly. However after days of going through the documentation I still can't seem to find a solution.
Currently my code is as follows:
df = px.data.gapminder().query("continent=='Oceania' ")
fig = px.line(df, x="year" , y="lifeExp", color="country" , animation_frame="year", animation_group="lifeExp" , range_y=[68,84] , range_x=[1950,2010])
plot(fig)
This however generates and empty plot. Please help.
I am able to successfully generate a scatter plot and a bar graph using similar code.
For better understanding please view below link :
I have found an exact example of what I am looking for implemented in R.
https://plot.ly/r/cumulative-animations/#cumulative-lines-animation
For the empty plot, try changing the default renderer by adding this above your code:
import plotly.io as pio
pio.renderers.default = 'notebook'
There is some documentation on different renderers.

Plotting chart with rounded rectangle in Python

I found an interesting chart illustrating the specific bands of different trace chemical atmospheric species that can be used for detecting on satellite.
The figure above use rounded rectangle presented for the spectral measurement range.
I want to reproduce this kind of art with python.
For now, I could use Plotly package for plotting table in the same style.
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.tools import FigureFactory as FF
fig = go.Figure()
data_matrix = [['Tracer gas/nm', '200', '300','400','500'],['HCHO', "", ],
['CHOCHO',],['BrO', ], ['O3', ],['O2', ],['NO2',]]
table = FF.create_table(data_matrix)
py.iplot(table, filename='simple_table')
# py.image.save_as(fig, filename='a-simple-plot.png')
The figure shows like this:
But I found two tricky problems:
(1) I couldn't save the chart into figure.
(2) I couldn't plot the rounded rectangle on the chart.
Any advice with better solution would be appreciated!

Categories