Adjust plotly-Dash table column width - pandas

I want to adjust the width of columns in Dash table (created from Pandas Dataframe). There are 3 columns in table :
Path
Scenario
Step
I want to set the column width of first column (Path) to 10% and the second column (Scenario) to 40% and the last column (Step) to 50%.
I am running below code, but the column width changes are not working as expected. "Path" column is taking more than 50% of width and "Steps" column around 20%.
Dataframe name is dfSteps
columns=[{"name": i, "id": i} for i in dfSteps.columns],
data=dfSteps.to_dict('records'),
style_header={
'backgroundColor': 'rgb(230, 230, 230)',
'fontWeight': 'bold'
},
style_table={
'maxWidth': '2000px',
'overflowX': 'scroll',
'border': 'thin lightgrey solid'
},
style_cell={
'font_family': 'cursive',
'font_size': '16px',
'border': '1px solid grey',
'minWidth': '1px', 'width': 'fixed', 'maxWidth': '1000px',
'textAlign': 'left', 'whiteSpace': 'normal'
},
style_cell_conditional=[
{'if': {'column_id': 'Path'},
'width': '10%'},
{'if': {'column_id': 'Scenario'},
'width': '40%'},
{'if': {'column_id': 'Path'},
'width': '50%'},
],
),

Just redefine your table as they suggest in the documentation
https://plotly.com/python/table/
fig = go.Figure(data=[go.Table(
columnorder = [1,2],
columnwidth = [80,400],
header = dict(
values = [['<b>EXPENSES</b><br>as of July 2017'],
['<b>DESCRIPTION</b>']],
line_color='darkslategray',
fill_color='royalblue',
align=['left','center'],
font=dict(color='white', size=12),
height=40
),
cells=dict(
values=values,
line_color='darkslategray',
fill=dict(color=['paleturquoise', 'white']),
align=['left', 'center'],
font_size=12,
height=30)
)
])
fig.show()

Related

missing data in pandas profiling report

I am using Python 2.7 and Pandas Profiling to generate a report out of a dataframe. Following is my code:
import pandas as pd
import pandas_profiling
# the actual dataset is very large, just providing the two elements of the list
data = [{'polarity': 0.0, 'name': u'danesh bhopi', 'sentiment': 'Neutral', 'tweet_id': 1049952424818020353, 'original_tweet_id': 1049952424818020353, 'created_at': Timestamp('2018-10-10 14:18:59'), 'tweet_text': u"Wouldn't mind aus 120 all-out but before that would like to see a Finch \U0001f4af #PakVAus #AUSvPAK", 'source': u'Twitter for Android', 'location': u'pune', 'retweet_count': 0, 'geo': '', 'favorite_count': 0, 'screen_name': u'DaneshBhope'}, {'polarity': 1.0, 'name': u'kamal Kishor parihar', 'sentiment': 'Positive', 'tweet_id': 1049952403980775425, 'original_tweet_id': 1049952403980775425, 'created_at': Timestamp('2018-10-10 14:18:54'), 'tweet_text': u'#the_summer_game What you and Australia think\nPlay for\n win \nDraw\n or....! #PakvAus', 'source': u'Twitter for Android', 'location': u'chembur Mumbai ', 'retweet_count': 0, 'geo': '', 'favorite_count': 0, 'screen_name': u'kaluparihar1'}]
df = pd.DataFrame(data) #data is a python list containing python dictionaries
pfr = pandas_profiling.ProfileReport(df)
pfr.to_file("df_report.html")
The screenshot of the part of the df_report.html file is below:
As you can see in the image, the Unique(%) field in all the variables is 0.0 although the columns have unique values.
Apart from this, the chart in the 'location' variable is broken. There is no bar for the values 22, 15, 4 and the only bar is for the maximum value only. This is happening in all the variables.
Any help would be appreciated.

c3 charts dynamic bubble size in scatter plot, wrong index

I'm trying to make a chart like with c3.js.
For the bubble size I create an array for each "continent" holding the population as a factor to increase the bubble size. Also the country name is stored in the same manner.
When adding the data points to the chart as well as when adding the bubble sizes/country names to the array, the indices are the same. E.g. col_2[0] in the bubbleInfo array is "China". Also in the data columns col_2[0] and col_2_x[0] are 76 and 12000 which are the values for China.
However, in the section where I dynamically get the bubble radius/country name, the index I get from the function parameter is not the one of the col_2 arrays. Instead I get the index in the order in which the dots are spead along the x-Axis.
E.g. I add for x-Axis China (12000), India(5800), Indonesia(9000) in this order.
I'd expect to get index 1 for India, but I get index 0, because 5800 is the lowest of the x values.
Because of that I cannot properly map the indices on the bubble sizes/country names, since the indices are wrong.
Is this a bug and if so, how can I properly map the bubble sizes/country names then?
Here is the JSFiddle:
var chart_3_bubbleSize = {
"col_2": [10.0, 9.0, 3.9, 2.5, ],
"col_1": [3.0, 2.5, ],
"col_3": [2.5, 5.5, ],
};
...
var chart_3_bubbleInfo = {
"col_2": ["China", "India", "Indonesia", "Japan", ],
"col_1": ["Russia", "Germany", ],
"col_3": ["Mexico", "USA", ],
};
...
columns: [
['col_2', 76, 66, 71, 86],
['col_2_x', 12000, 5800, 9000, 36000],
['col_1', 72, 80.4],
['col_1_x', 25000, 40000],
['col_3', 76, 78],
['col_3_x', 16000, 50000],
],
...
point:
{
r: function(d)
{
/*d.index gives the index according to the order along the x-axis, which leads to wrong result, when trying to map to country names/bubble sizes*/
return 2 * chart_3_bubbleSize[d.id][d.index];
}
},
https://jsfiddle.net/51oLxqyt/1/
The first green bubble in the lower left corner should be India, but it has the label "China" and the bubble size of China, because China is at index 0 in the bubbleInfo and bubbleSize arrays.
There is an not documented attribute data.xSort = false, which keeps the original index, which makes it possible to map more dimension e.g. for scatter charts.
More info here: https://github.com/c3js/c3/issues/547#issuecomment-56292971

Single word per line in kivy(GridLayout)

I'm trying to make a app similar a menu. I already did scrollview with gridLayout, but I don't know how to show this separate, for instance, in the left column names, and in the right column age, in this way the app may have variable number of rows (infinity). I hope I have been less confusing as possible, the same for my english. Thanks everybody, I didn't post my code here because I think it isn't necessary. Bye, have a good day.
Ass is important I post my code here, I'm going to try to post. I'm sorry for the mistakes like indent.
.py
class PrimeiroScreen(Screen):
def __init__(self, **kwargs):
self.name = 'home'
super(Screen,self).__init__(**kwargs)
class SegundoScreen(Screen):
text = StringProperty('')
def __init__(self, **kwargs):
self.name = 'dois'
super(Screen,self).__init__(**kwargs)
class RootScreen(ScreenManager):
pass
class scrollmanageApp(App):
def build(self):
return RootScreen()
if __name__ == '__main__':
appVar = scrollmanageApp()
scrollmanageApp().run()
.kv
<RootScreen>:
PrimeiroScreen:
SegundoScreen:
<PrimeiroScreen>:
BoxLayout:
size_hint: (.3,.15)
pos_hint:{'x': .35, 'y': .84}
Label:
text: "Teste de uniĆ£o scrollview com screenmanage"
font_size: '30dp'
GridLayout:
cols: 1
rows: 2
size_hint: (.20,.10)
pos_hint:{'x': .25, 'y': .64}
Button:
text: "Scrollview!"
font_size: '30dp'
text_size: self.size
on_press: root.manager.current = 'dois'
<SegundoScreen>:
text: 'This is just a test ' * 50
ScrollView:
size_hint: 1, 1
pos_hint:{'x': .0, 'y': .0}
size: 100, 100
GridLayout:
cols: 2
#rows:
padding: 10
spacing: 10
size_hint: None, None
width: 500
height: self.minimum_height
Label:
text: root.text
font_size: 50
text_size: self.width, None
size_hint_y: None
height: self.texture_size[1]
Button:
text: "Voltar!"
size_hint: .1, .1
pos_hint:{'x': .9, 'y': .0}
text_size: self.width, None
on_press: root.manager.current = 'home'
I hope I had sucess in this time(post my code).Very thanks!

Setting a max axis value or range step for a Morris Bar Chart?

I was wondering if it is possible to set a max axis value (say, I want the highest point of my data to be the top end of the y-axis) on a bar chart? I see there are options for ymin and ymax on line charts but I can't seem to find any information about the bar charts.
Also, it would be helpful if anyone knew how to force the range between axis lanes to be a certain amount (say step up by 250 each line instead of the generated amount which in my case is too high for my liking).
Set a maximum value for the y axis
You can, indeed, set the ymax for bar charts also (even though this is not documented).
Morris.Bar({
element: 'bar-example',
data: [
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 }
],
xkey: 'y',
ymax: 300, // set this value according to your liking
ykeys: ['a', 'b'],
labels: ['Series A', 'Series B']
});
And have your y axis set to this maximum value:
Set a range value for the y axis
It seems that it's not possible to set a range value for the y axis. This value appears to be computed according to the values of the data passed to Morris.Bar.
Not documented, but you can set maximum y by applying ymax. You can manipulate the range by setting numLines (also not documented).
E.g.
var chart = new Morris.Bar({
...
ymin: 0,
ymax: 7,
numLines: 8,
...
});
The above defined chart will display values from 0 to 7 and display a grid line for each integer between 0 and 7 (therefore 8 as a parameter)
To change to ymax call this
chart.options["ymax"] = 300;
Where chart is your chart variable
I want the highest point of my data to be the top end of the y-axis
The documentation is very sparse and confusing but this is possible using the ymin variable which is only documented in the Lines & Area Charts. The default value for that variable seems to be auto 0 and changing it to just auto seems to produce the desired result as you can see below.
how to force the range between axis lanes to be a certain amount
This does not seem to be possible, natively. However, you can kind of hack the axis label with the following function. It will round the value to multiples of 250 BUT the grid lines won't be at the number shown. E.g. say a grid line is at 570. The function below will change the label to 500 but the line will still show at 570 mark.
yLabelFormat: function(d) {
return Math.round(d) - (Math.round(d) % 250);
},
As others have mentioned, you can set ymax to a value that you want your upper bound to be but since you want the highest data point to be the upper bound, set ymax to auto. You can also try changing numLines to different values for a better aesthetic.

Dojox chart number of Y axis labels

When I create a DojoX vertical bar chart, it automatically calculates the labels on the Y axis to cover the largest value. In this case, it created 3 Y-axis labels, 100, 200 300.
How do I increase the number of labels, to say intervals of 50 rather than intervals of 100?
When you add an axis, there are several options you can use for the tick marks. Example:
chart.addAxis("y", {
majorTicks : true, // default
majorLabels : true, // default
majorTick : {length: 4, color: "#FFF"},
majorTickStep : 10,
minorTicks : true,
minorLabels : true,
minorTick : { length: 2, color: "#CCC"},
minorTickStep : 5,
...
vertical: true
});
Check the API docs for more: http://dojotoolkit.org/api/1.8/dojox/charting/axis2d/Default