Created
June 21, 2024 15:58
-
-
Save lemire/975b4db6a932fa47657410b5f3d87815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import plot_likert | |
q1 = "pertinence" | |
q2 = "sentiment de\ncompétence" | |
q3 = "expérience" | |
myscale = ['Fortement en désaccord', 'Plutôt en désaccord',"Plutôt d'accord", "Fortement d'accord"] | |
precomputed_counts = pd.DataFrame( | |
{myscale[0]: {q1: 1, q2: 1, q3:1}, | |
myscale[1]: {q1: 2, q2: 1, q3:1}, | |
myscale[2]: {q1: 7, q2: 5, q3:10}, | |
myscale[3]: {q1: 10, q2: 12, q3:7} | |
} | |
) | |
print(precomputed_counts)#plot_likert.colors.likert4 | |
az = plot_likert.plot_counts(counts=precomputed_counts, colors = plot_likert.colors.likert4,scale=myscale, bar_labels=True, plot_percentage=False, figsize=(10,5)) | |
az.set_xlabel("Répondants") | |
#legend = az.get_legend() | |
#legend.set_bbox_to_anchor((1.5, 5)) | |
az.spines['top'].set_visible(False) | |
az.spines['right'].set_visible(False) | |
az.spines['left'].set_visible(False) | |
az.tick_params(left = False) | |
#az.spines['bottom'].set_visible(False) | |
#az.set_yticks('off') | |
box = az.get_position() | |
az.set_position([box.x0, box.y0, box.width * 0.8, box.height]) | |
az.legend(loc='center left', bbox_to_anchor=(1, 0.5)) | |
az.get_legend().get_frame().set_linewidth(0.0) | |
#az.get_legend().remove() | |
import matplotlib.pyplot as plt | |
from matplotlib.backends.backend_pdf import PdfPages | |
# Assuming you have already created the plot 'az' using plot_likert | |
# Save the plot to a PDF file | |
with PdfPages('likert_plot.pdf') as pdf: | |
pdf.savefig(az.figure) | |
plt.close() | |
print("The likert plot has been saved to likert_plot.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment