altair bar chart text issue - bar-chart

this is my code ...please correct so that label will show correct count.
tool tip is showing correct count.
bars =alt.Chart(r).transform_fold(
['Reservation_count', 'ON_ACCOUNT'],
as_=['column', 'value']
).mark_bar().encode(
x='month:N',
y='value:Q',
color=alt.Color('column:N', scale=alt.Scale(range=["#f50520", "#bab6b7"])),
tooltip=alt.Tooltip(['ON_ACCOUNT','Reservation_count']),
)
text = bars.mark_text(
align='left',
color='black',
baseline='middle',
dx=0,dy=-8 # Nudges text to right so it doesn't appear on top of the bar
).encode(
text=alt.Text('ON_ACCOUNT:Q', format='.0f')
)
rule = alt.Chart(r).mark_rule(color='red').encode(
y='mean(Reservation_count):Q'
)
(bars+text+rule).properties(width=490,height=310)
below is my data:
month ON_ACCOUNT Reservation_count
0 1 22 134
1 2 32 137
2 3 22 135
3 4 21 113
4 5 18 120
5 6 17 90
6 7 26 83
7 8 11 86
8 9 11 102
9 10 2 68
please help me with this altair bar chart..two columns are there Reservation_count and ON_ACCOUNT LABEL IS showing the same number for both ...
Thanks
for example last bar showing 2,2 both labels it should be top 2 and bottom 68

The short version answer to your question is to use text=alt.Text('value:Q', format='.0f').
But there are a few more issues with your code:
You are expanding your text layer from the bar plot, which already has the color parameter set. This will ignore the color setting of the text layer.
You can use a data encoding free from any color specification. You can then use this encoding to build your bar and text layers with their color settings.
I encountered the text ordering issue discussed here, and none of the given solutions worked out. However, changing the plot from vertical bar to horizontal bars seem to resolve the issue. This is potentially a bug.
Since you are plotting the mean of Reservation_count parameter on a stacked plot, the information might be misleading. I would suggest a layered bar instead of a stacked one. Surprisingly, this seems to solve the issue of text order.
Here is the code:
base =alt.Chart(r).transform_fold(
['Reservation_count', 'ON_ACCOUNT'],
as_=['column', 'value']
)
bars = base.mark_bar().encode(
x='month:N',
y=alt.X('value:Q', stack=None), # stack =None enables layered bar
color=alt.Color('column:N', scale=alt.Scale(range=["#f50520", "#bab6b7"])),
tooltip=alt.Tooltip(['ON_ACCOUNT','Reservation_count']),
#order=alt.Order('color_Category_sort_index:Q'),
)
text = base.mark_text(
align='center',
color='black',
baseline='middle',
dx=0,dy=-8, # Nudges text to right so it doesn't appear on top of the bar
#order=alt.Order('color_Category_sort_index:Q'),
).encode(
x='month:N',
y='value:Q',
text=alt.Text('value:Q', format='.0f')
)
rule = alt.Chart(r).mark_rule(color='red').encode(
y='mean(Reservation_count):Q'
)
(bars+text+rule).properties(width=490,height=310)

Related

I am not able to change the column width in horizontal sns.barplot and make the figure look good

I am trying to generate an horizontal barplot from this dataframe:
Question Answer Value in % postpand
0 a Yes 34.2 postpand
1 a No 65.8 postpand
2 b Positive 32.1 postpand
3 b Negative 65.0 postpand
4 b No Change 2.9 postpand
5 c Yes 70.4 postpand
6 c No 14.5 postpand
7 d Yes 84.2 postpand
8 d No 15.8 postpand
9 e Yes 70.4 postpand
10 e No 29.2 postpand
11 f Yes 49.2 postpand
12 f No 50.4 postpand
(please, disregard de column "postpand")
Now making the figure...
ax = sns.barplot(x="Value in %", y="Question", data=df, hue="Answer")
plt.ylabel("Question and Answer", fontsize=40)
plt.xlabel("Value in %", fontsize=40)
ax.set_xlim (xmax=100)
plt.show()
So for me, there seems to be several things unpleasant about this figure:
First, I would like the bars to be so thick as to occupy the space more fully, and also to be centered with the categories in y-axis.
Second, the legend is hiding the bars.
For the thickness of the bars, I found a code that might be helpful to change their width in the x-axis. I had to "adapt" it to height, since it is horizontal, but I think I got to not give an error jus by pure luck. So now this is the code:
sns.set(font_scale=3, style="whitegrid")
ax = sns.barplot(x="Value in %", y="Question", data=df, hue="Answer")
def change_height(ax, new_value) :
for patch in ax.patches :
current_height = patch.get_height()
diff = current_height - new_value
# we change the bar height
patch.set_height(new_value)
# we recenter the bar
patch.set_y(patch.get_y() + diff * 0.5)
change_height(ax, .35)
plt.ylabel("Question and Answer", fontsize=40)
plt.xlabel("Value in %", fontsize=40)
ax.set_xlim (xmax=100)
plt.show()
However, this is not a nice looking figure either. I have played with several combinations of parametres ("diff * 0.5", and "change_height(ax, .35)") with no better results. Still not occupying the space beautifully and still uncentered...
Anyone could guide me in what I could do?
Many thanks in advance for your help, guys!

Sequence of content changed while using multiple columns css3 in safari

Kindly find my code here I got content sequence like as 1 3 2 4 in safari whereas it is fine in all other browsers.I used multiple column css3.
For example, I am having content as
சென்னை, மதுரை என 30-க்கும் மேற்பட்ட இடங்களில்
நடைபெற்ற
Below is my output (after column division) in chrome,firefox,ie,edge
1 2 3 4
சென்னை, மதுரை | என 30-க்கும் |மேற்பட்ட| இடங்களில்
In ipad safari and mac safari
1 3 2 4
சென்னை, மதுரை |இடங்களில்| என 30-க்கும்| மேற்பட்ட
Can anyone please help me to fix it.
Thanks

How to add a list in front of current list in Sublime Text

I need to add a list of names in front of a current list of number in sublime and having a hard time figuring out how to do it.
Basically if I have list 1
Tom
Jerry
Mary
Sue
and
12
34
45
39
I need the final text file to read
12 Tom
34 Jerry
45 Mary
39 Sue
I would do it by hand, but its around 800 entries each with about 25 sets of numbers after it.
Thanks!
select list 1
press Ctrl + Shift + L to split the selection into lines
cut the selected lines
select list 2
press Ctrl + Shift + L to split the selection into lines
press End to go to the end of each line & add a space character
paste the previously copied text
Note:
This only works if both selections have the same number of lines.

Report with combined fields

I need to create report to render like image below:
So, for each question, I have several answers (4 or 5 answers), and every question have belonging image.
DATASET:
QuestionId QuestionName Image AnswerId AnswerText
1 Question 1 Image 1 Answer 11
1 Question 1 Image 1 Answer 12
1 Question 1 Image 1 Answer 13
1 Question 2 Image 1 Answer 21
1 Question 2 Image 1 Answer 22
1 Question 2 Image 1 Answer 23
1 Question 3 Image 1 Answer 31
1 Question 3 Image 1 Answer 32
1 Question 3 Image 1 Answer 33
To do this I have made the following assumption
You want each Question Text to appear as a new question with it's own associated answers
I would implement this using a List in SSRS
Add a new List item, and set it's DataSetName to your Dataset. (I have also set the BorderStyle to Solid in the example below)
Right click the Row Header, and select Row Group -> Group Properties, then Group on QuestionName
Within the body of the list item, draw a textbox for the Question name, and Create a Placeholder in it with the value =Fields!QuestionName.Value
Add a new image box, and set it to use the image =Fields!Image.Value
Finally add a new table, and set the data to be =Fields!AnswerText.Value. (You may also want to remove the header row)
The final layout should be something like this
And when run will render as
Hopefully this is the sort of thing you are after. If not then let us know to provide further assistance.

how to show two spaces at the end of a sentence (redux)

Ok, deep breath.
Suppose one is using a monospace font and has three requirements. This may or may not be wise; that's not what I'm asking.
Show two spaces at the end of each sentence in a web page, provided the sentence ends in midline.
But if the sentence ends in mid-paragraph but happens to approach the right margin, the final character (typically ".") should be able to nestle as close to that right margin as any other character in any other line. That is, carefully tweaking the window width while viewing the test results ought to be able to squeeze out any space following the pre-gap text.
Similarly, no extraneous space must be introduced after the line break.
To be able to justify the text is not a requirement.
A similar question has already been asked here. But that thread has two problems (for me):
It was rightly closed, because the discussion bogged down in whether the requirement was wise in the first place. I do not assert the wisdom of the above requirements; I simply ask the question.
The initiator did not seem to worry about requirement 2 above, so the discussion did not fully address it.
I have tried placing each of the following between two sentences. Each of them either did not fulfill one of the requirements, or completely failed to allow a line break between the two sentences. As you read this list, add semicolons where they seem appropriate; when I added them to the actual list, I got real spaces and stuff, not the names of the entities.
(space)(space)
&emsp&emsp
(space)&emsp
&emsp(space)
&ensp&ensp
(space)&ensp
&ensp(space)
&nbsp&nbsp
(space)&nbsp
&nbsp(space)
(space)(space-within-span)
(space-within-span)(space)
(space-within-span)(space-within-span)
In addition, I tried the white-space: pre-wrap idea, which failed requirement 2.
What do you suggest? In my tests, the stylesheet is this:
P.intro
{
font-family: Courier, monospace;
}
P.prewrap
{
font-family: Courier, monospace;
white-space: pre-wrap;
}
... and the web page is this:
<HTML><HEAD>
<link rel="stylesheet" href="style.css">
</HEAD><BODY>
<P class=intro>
01 alpha spacespace omega spacespace<BR>
<BR>
02 alpha &emsp;&emsp;  omega &emsp;&emsp;<BR>
03 alpha space&emsp;  omega space&emsp;<BR>
04 alpha &emsp;space  omega &emsp;space<BR>
<BR>
05 alpha &ensp;&ensp;  omega &ensp;&ensp;<BR>
06 alpha space&ensp;  omega space&ensp;<BR>
07 alpha &ensp;space  omega &ensp;space<BR>
<BR>
08 alpha &nbsp;&nbsp; omega &nbsp;&nbsp;<BR>
09 alpha space&nbsp; omega space&nbsp;<BR>
10 alpha &nbsp;space omega &nbsp;space<BR>
<BR>
11 alpha space-spanspace <SPAN> </SPAN>omega space-spanspace<BR>
12 alpha spanspace-space<SPAN> </SPAN> omega spanspace-space<BR>
13 alpha spanspace-spanspace<SPAN> </SPAN><SPAN> </SPAN>omega spanspace-spanspace<BR>
<BR>
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2
<BR>
01 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3
</P>
<P class=prewrap>Lorem ipsum. Dolor sit amet.</P>
</BODY></HTML>
Include this in your css file:
SPAN.eos
{
word-spacing: 0.625em
}
Do this at the end of each midparagraph sentence:
finalword<SPAN class=eos>. B</SPAN>eginning