Add individual Axis Labels to PyQT chart in Python? - user-interface

I'm in the final portion of my project and we just need to make a graph showing the number of shows and movies with their rating trend. I have 4 different bar graph items and I was wondering if there's a way to add labels to each individual bar? For example here's one of the bars
y4 = [fourth]
x4 = [4.33]
bg4 = pg.BarGraphItem(x=x4, height=y4, width=0.2, brush='red', setLabel="Shows Down")
bg4.setX(0)
bg4.setY(0)

You could use a group of TextItem and set the bar as their parent:
text = pg.TextItem('Some bar', angle=90, color='#ffff00')
# reparent the item and make it a child of the bar
text.setParentItem(bg4)
# set the position to the x of the bar
text.setX(x4[0])
# use the x as left of the text and the y as vertical middle (referenced
# to the text orientation)
text.setAnchor(QPointF(0, .5))
Note that you don't need to create individual bars as long as they are part of the same group and share the same colors: just add the x and height as lists of their positions and values.

Related

Seaborn: Place the y-label in a line with the points on the coordinate axis

I want to place the y-label in the left upper corner in line with the points on the coordinate axis. The label should replace the axes ticks in that area.
Here is an example from a paper that I read:
I found a lot of information on how to move the label to the top left corner. However, how do I remove the ticks and move the label closer to the axes?
The best solution that I found:
# style
plt.figure(figsize=(8,8))
sns.set_style("white")
sns.set_context("paper", font_scale=1.6)
# plot
sn_dis1 = sns.displot(idx_pix_count_pd, hue='Dataset', x="Size", fill=True, palette='bwr', kind="hist", bins=500)
# y-achses
axes = sn_dis1.axes.flatten()
axes[0].set_ylabel("Count", fontsize=16)
axes[0].yaxis.set_label_coords(.0, .9)
The approach proposed by Trenton (Edit: Who delete his comment to my original question) did not work for me as the text is horizontal vertically. But I learned something from it and am sure that you somehow can make it work like that.
# style
plt.figure(figsize=(8,8))
sns.set_style("white")
sns.set_context("paper", font_scale=1.6)
# plot
sn_dis1 = sns.displot(idx_pix_count_pd, hue='Dataset', x="Size", fill=True, palette='bwr', kind="hist", bins=500)
# y-achses
ticks = range(8)
labels= list(range(7)) + ['Density']
axes = sn_dis1.axes.flatten()
axes[0].set_yticklabels(labels)
# do not show default label
axes[0].get_yaxis().get_label().set_visible(False)

Visual Studio - Range chart - Adding background colours per category group

I am using a Range chart to create a Gannt Chart of sorts. I am attempting to do two things:
1) Change the background colour of the range chart based upon one of two Category groups, I have two groups, an outer and an inner, and I would like the background colour to change based on the outer grouping. I have a piece of code that determines a colour but, i'm having trouble applying that to the background. I was hoping interlacing colour would help me, that you aren't able to determine the frequency of the interlacing from what I can tell.
The code I'm using is:
Private colorPalette As String() = { "#C85200", "#FF800E", "#5F9ED1",
"#2CA02C", "#A59D93", "#B8341B", "#352F26", "#F1E7D6", "#E16C56", "#CFBA9B"}
Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()
Public Function GetColor(ByVal groupingValue As String) As String
If mapping.ContainsKey(groupingValue) Then
Return mapping(groupingValue)
End If
Dim c As String = colorPalette(count Mod colorPalette.Length)
count = count + 1
mapping.Add(groupingValue, c)
Return c
End Function
2) Position the X and Y axis labels between the major grid lines. The X axis is a date, and the end user would like the date to be between the two grid lines (representing a day) rather than on each grid line, I've had a look around but can't seem to find anything relevant.
Any help or guidance would be appreciated, thanks!

D3 Outer padding - padd the left bar only

I have a two column vertical bar chart.
I dont want the left hand bar to be flush with the Y axis.
So I used PaddingOuter() to specify an inset as follows:
var x = d3.scaleBand().rangeRound([0, width]).paddingInner(0.1).paddingOuter(0.5).align(0.1);
I works nicely.
Except that the right hand bar (its a two column chart) is also inset.
I only want the left hand bar inset.
Is there a solution to this..?
Start the range at the amount you want to offset by, e.g., rangeRound([10, width])

d3 autospace overlapping tick labels

Is there a way in d3 to not draw overlapping tick labels? For example, if I have a bar chart, but the bars are only 5 pixels wide and the labels are 10 pixels wide, I end up with a cluttered mess. I'm currently working on an implementation to only draw the labels when they do not overlap. I can't find any existing way to do that, but wasn't sure if anyone else had dealt with this problem.
There is no way of doing this automatically in D3. You can set the number of ticks or the tick values explicitly (see the documentation), but you'll have to figure out the respective numbers/values yourself. Another option would be to rotate the labels such that there is less chance of them overlapping.
Alternatively, like suggested in the other answer, you could try using a force layout to place the labels. To clarify, you would use the force layout on the labels only -- this is completely independent of the type of chart. I have done this in this example, which is slightly more relevant than the one linked in the other answer.
Note that if you go with the force layout solution, you don't have to animate the position of the labels. You could simply compute the force layout until it converges and then plot the labels.
I've had a similar problem with multiple (sub-)axis, where the last tick overlaps my vertical axis in some situations (depending on the screen width), so I've just wrote a little function that compares the position of the end of the text label with the position of the next axis. This code is very specific to my use case, but could adapted easily to your needs:
var $svg = $('#svg');
// get the last tick of each of my sub-axis
$('.tick-axis').find('.tick:last-of-type').each(function() {
// get position of the end of this text field
var endOfTextField = $(this).offset().left + $(this).find('text').width();
// get the next vertical axis
var $nextAxis = $('line[data-axis="' + $(this).closest('.tick-axis').attr('data-axis') + '"]');
// there is no axis on the very right, so just use the svg width
var positionOfAxis = ($nextAxis.length > 0) ? $nextAxis.offset().left : $svg.offset().left + $svg.width();
// hide the ugly ones!
if (endOfTextField > positionOfAxis) {
$(this).attr('class', 'tick hide');
}
});
The ticks with color: aqua are the hidden ones:

How can I control the width of the X-axis labels on a horizontal bar RadChart?

What are the properties that control the width of the X-axis labels on a horizontal bar RadChart? Here's what it looks like now:
I need the labels on the left to be wider.
I actually, just needed to keep the auto layout doing its thing, and disable auto wrapping this way:
var item = new ChartAxisItem();
item.Appearance.RotationAngle = AutoTextWrap.False

Resources