Skip to content

Instantly share code, notes, and snippets.

@casperboone
Last active May 4, 2021 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save casperboone/d1b39662cab73549142ae21e61b94fd1 to your computer and use it in GitHub Desktop.
Save casperboone/d1b39662cab73549142ae21e61b94fd1 to your computer and use it in GitHub Desktop.
Tiny Likert Plots
import plotly.graph_objects as go
import numpy as np
from slugify import slugify
from results.process_input import process_intro, process_questions_intro
from results.report import color
def tiny_likert(answers):
fig = go.Figure([
# Base markers
go.Bar(x=np.arange(1, 6), y=np.repeat(np.max(answers.values) * 0.05, 5), marker_line_width=0, marker_color=color.gray),
# Likert bars
go.Bar(x=answers.index, y=answers.values, marker_line_width=0, marker_color=color.testaxis_brand)
])
fig.update_layout(
width=160,
height=96,
xaxis_range=[0.5, 5.5],
yaxis_range=[0, np.max(answers.values)],
margin=dict(t=0, r=0, b=0, l=0),
yaxis_visible=False,
xaxis_visible=False,
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
bargap=0.1,
showlegend=False,
barmode='stack'
)
return fig
# Usage example
# (I have a main script calling all `generate` functions of the plot scripts in a subdirectory that outputs the plots as PDFs)
def generate():
df_intro = process_intro()
df_intro_questions = process_questions_intro()
intro_questions = df_intro_questions[df_intro_questions['type'] == 'likert']['question']
return dict(
[
(
slugify(question),
tiny_likert(df_intro[question].value_counts().sort_index())
)
for question in intro_questions
]
)
def separate_directory():
return True
% Tiny Likert
% Based on https://tex.stackexchange.com/questions/258299/embed-small-image-within-a-line-of-text
% (likely requires some customization)
\newcommand*{\tinylikert}[1]{%
\raisebox{-.2\baselineskip}{%
\includegraphics[
height=.8\baselineskip,
]{#1}%
}%
}
\begin{document}
This is an example (\tinylikert{plots/tinylikert/i-consider-myself-to-be-experienced-in-developing-software-applications.pdf}).
\end{document}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment