Different dashtype in the same plot (Gnuplot 4.6.6) - line

I am using epscairo terminal.
I have 10 lines in one plot and I defined line styles such as:
set style line 1 linetype 1 lw 1 linecolor rgb 'black'
set style line 2 linetype 2 lw 1 linecolor rgb 'black'
set style line 3 linetype 3 lw 1 linecolor rgb 'black'
set style line 4 linetype 4 lw 1 linecolor rgb 'black'
set style line 5 linetype 5 lw 1 linecolor rgb 'black'
set style line 6 linetype 6 lw 1 linecolor rgb 'black'
set style line 7 linetype 7 lw 1 linecolor rgb 'black'
set style line 8 linetype 8 lw 1 linecolor rgb 'black'
set style line 9 linetype 9 lw 1 linecolor rgb 'black'
set style line 10 linetype 10 lw 1 linecolor rgb 'black'
I want all the lines to be black as it is set.
Epscairo terminal repeats line patters each 6th line, i.e. :
- linetype 6 is the same as linetype 1 if do not change color or thickness
- linetype 7 is the same as linetype 2 if do not change color or thickness
- etc.
I read this topic but it didn't help:
Gnuplot line types
I want to use different dashtypes (if that is the option) in the same plot, for example from 1-5 I want to use dashes, and from 6-10 I want to use symbols (squares, circles, triangles etc).
Is that possible and how can I do that?
Thank you! :)

Related

Subplots with counter like legends

I have written plot_dataframe() to create two subplots (one for line chart and another for histogram bar chart) for a dataframe that is passed via argument.
Then I call this function from plot_kernels() with multiple dataframs.
def plot_dataframe(df, cnt):
row = df.iloc[0].astype(int) # First row in the dataframe
plt.subplot(2, 1, 1)
row.plot(legend=cnt) # Line chart
plt.subplot(2, 1, 2)
df2 = row.value_counts()
df2.reindex().plot(kind='bar', legend=cnt) # Histogram
def plot_kernels(mydict2):
plt.figure(figsize=(20, 15))
cnt=1
for key in my_dict2:
df = my_dict2[key]
plot_dataframe(df, cnt)
cnt = cnt + 1
plt.show()
The dictionary looks like
{'K1::foo(bar::z(x,u))': Value Value
0 10 2
1 5 2
2 10 2, 'K3::foo(bar::y(z,u))': Value Value
0 6 12
1 7 13
2 8 14}
And based on the values in row[0], [10,2] are shown in blue line and [6,12] are shown in orange line. For histogram, they are similar. As you can see the legends in the subplots are shown as 0 in the figure. I expect to see 1 and 2. How can I fix that?
Change legend to label, then force the legend after you plot everything:
def plot_dataframe(df, cnt,axes):
row = df.iloc[0].astype(int) # First row in the dataframe
row.plot(label=cnt, ax=axes[0]) # Line chart -- use label, not legend
df2 = row.value_counts()
df2.plot(kind='bar', ax=axes[1], label=cnt) # Histogram
def plot_kernels(d):
# I'd create the axes first and pass to the plot function
fig,axes = plt.subplots(2,1, figsize=(20, 15))
cnt=1
for key in d:
df = d[key]
plot_dataframe(df, cnt, axes=axes)
cnt = cnt + 1
# render the legend
for ax in axes:
ax.legend()
plt.show()
Output:

Making pandas.plot legend and stacks in the same specified order

I have a stacked bar plot that I want to display the legend and stacks in the specified same order.
In order the sort the legend classes, I added 1, 2 in front of True, False (the classes I want to sort). Not the most ideal way but it works. The problem is, it doesn't sort the stacks.
Example data
d = {'sel_date':['2020-01', '2020-01', '2020-01', '2021-02', '2021-03', '2020-01', '2020-01', '2020-01', '2021-02', '2021-03'], \
'id':list('yyzzz'*2), \
'is_new': ['1. True', '1. True', '2. False', '1. True', '2. False', '1. True', '1. True', '2. False', '2. False', '2. False'], \
'Short Name':list('ababa'*2)}
d
df = pd.DataFrame(data=d)
df
sel_date id is_new Short Name
0 2020-01 y 1. True a
1 2020-01 y 1. True b
2 2020-01 z 2. False a
3 2021-02 z 1. True b
4 2021-03 z 2. False a
5 2020-01 y 1. True a
6 2020-01 y 1. True b
7 2020-01 z 2. False a
8 2021-02 z 2. False b
9 2021-03 z 2. False a
Plot by this function
def plot_stacked_barplot_example(feature, suptitle=None, df=reg, groupby_column='Short Name'):
sns.set_theme(style='white', font_scale=1.4)
fig, ax = plt.subplots(figsize=(30, 20))
for i, (group, data) in enumerate(df.groupby(groupby_column)):
ax = plt.subplot(2, 2, i+1)
pivot = (data.groupby('sel_date')[feature].value_counts(normalize=True)
.mul(100).unstack(feature)
.plot(kind='bar', stacked=True, ax=ax
))
ax.yaxis.set_major_formatter(mtick.PercentFormatter())
ax.xaxis.set_ticks([]) # Hide labels from xticks
ax.get_legend().remove()
handles, labels = ax.get_legend_handles_labels()
# sort both labels and handles by labels
labels, handles = zip(*sorted(zip(labels, handles), key=lambda t: t[0]))
ax.legend(handles, labels, bbox_to_anchor=(1, 1), loc='upper left')
plot_stacked_barplot_example(df=df, feature='is_new')
I'd like the stacks in the same order as the legend.

SSRS Color Gradient

I've been able to figure out how to make certain values the certain colors I would like. However, I'd really like to be able to create a color gradient so that it's more of a gradual change between each value.
0 = white
from white to green between 1 and 15,
gradient from green to yellow between 16 and 25,
and gradient from yellow to red between 26 and 35,
anything above 35 is red.
This is the code I have in the background fill expression:
=SWITCH(
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) = 0, "White",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 1 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) <= 15), "Green",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 16 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) <= 25), "Yellow",
((Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) >= 26 and
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value))) <= 35, "Orange",
(Sum(Fields!Total_Transaction_Count.Value) / CountDistinct(Fields!TransUserNumber.Value)) > 35, "Red")
This is the matrix I have so far
Take a look at this answer I wrote a while back. It's for a chart but the principle should be the same.
the basic idea is to calculate the colour in SQL and then use that to set the color properties in SSRS
Applying Custom Gradient to Chart Based on Count of Value
Keeping it all in SSRS
If you want to keep this within the report you could write a function to do the calculation.
For a very simple red gradient, it might look something like this..
Public Function CalcRGB (minVal as double, maxVal as double, actualVal as double) as String
Dim RedValue as integer
Dim GreenValue as integer
Dim BlueValue as integer
RedValue = ((actualVal - minVal) / (maxVal - minVal)) * 256
GreenValue = 0
BlueValue = 0
dim result as string
result = "#" & RedValue.ToString("X2") & greenValue.ToString("X2") & BlueValue.ToString("X2")
Return result
End Function
In this function I have set green and blue to 0 but these could be calculated too based on requirements.
To use this function as a background colour, set the Background Color property to something like
=Code.CalcRGB(
MIN(Fields!myColumn.Value),
MAX(Fields!myColumn.Value),
Fields!myColumn.Value
)

Pandas dataframe dump to excel with color formatting

I have a large pandas dataframe df as:
Sou ATC P25 P75 Avg
A 11 9 15 10
B 6.63 15 15 25
C 6.63 5 10 8
I want to print this datamframe to excel file but I want to apply formatting to each row of the excel file such that following rules are applied to cells in ATC and Avg columns:
colored in red if value is less than P25
colored in green if value is greater than P75
colored in yellow if value is between P25 and P75
Sample display in excel is as follows:
I am not sure how to approach this.
You can use style.Styler.apply with DataFrame of styles with numpy.select for filling by masks created by DataFrame.lt and
DataFrame.gt:
def color(x):
c1 = 'background-color: red'
c2 = 'background-color: green'
c3 = 'background-color: yellow'
c = ''
cols = ['ATC','Avg']
m1 = x[cols].lt(x['P25'], axis=0)
m2 = x[cols].gt(x['P75'], axis=0)
arr = np.select([m1, m2], [c1, c2], default=c3)
df1 = pd.DataFrame(arr, index=x.index, columns=cols)
return df1.reindex(columns=x.columns, fill_value=c)
df.style.apply(color,axis=None).to_excel('format_file.xlsx', index=False, engine='openpyxl')

Change Linetype of geom_hline Without Changing the Legend Title

I am pretty new to R so please excuse me if I got this wrong.
I am trying to change a dashed linetype of a geom_hline in ggplot2 to a solid one.
Any help is much appreciated!
Usually this is easily done with changing linetype = "dashed" to linetype = "solid". But since I have to use linetype for the text in my legend I cannot do this. Also adding linetype = "solid" after color results in
Error in [[<-.data.frame (tmp, i, value = c("blue", "blue")) :
Replacement has 2 lines, Data has 1`
This is the code that I am trying to adjust:
geom_hline(aes(yintercept = 5, linetype = "Title 1"), colour = "blue") +
geom_hline(aes(yintercept = 2, linetype = "Title 2"), colour = "blue") +
scale_linetype_manual(name = "", values = c(2, 2),
guide = guide_legend(override.aes = list(color = c("blue", "blue"))))