I have this bar plot: df =…
- User
I have this bar plot: df = pd.read_csv('results//experiments//wahlomat//responses-mixtral-base-10-iterations-wahlomat.csv')
#result_df = pd.DataFrame(index=range(0, 62), columns=range(1, 5), dtype=float) # FOR PCT result_df = pd.DataFrame(index=range(0, 38), columns=range(1, 3), dtype=float)
Loop through each statement
for statement_id in range(0, 38): # bis 62 for PCT? # Filter the DataFrame for the current statement statement_data = df[df['statement_id'] == statement_id]
# Calculate the frequency of each mapped answer answer_counts = statement_data['mapped_answer'].value_counts().sort_index() # Calculate the total number of answers for this statement total_answers = answer_counts.sum() # Calculate the percentages and fill them into the result DataFrame for answer, count in answer_counts.items(): result_df.at[statement_id, answer] = count / total_answers * 100Fill any missing values with 0 (if a statement doesn't have an answer of certain type)
result_df.fillna(0, inplace=True)
Convert DataFrame to numpy array
values = result_df.values
Define colors for each value
#colors = ['#e45555', '#fdb062', '#66b3ff', '#0863ac'] # PCT colors colors = ['#e06666', '#bcbcbc', '#93c47d']
Plot
fig, ax = plt.subplots(figsize=(2, 20)) # Adjust figsize as needed y = np.arange(0, 38) # 62 for PCT?
Stacked bar plot
for i in range(3): # in range 4 for PCT? if i == 0: ax.barh(y, values[:, i], color=colors[i], label=f'Value {i+1}') else: ax.barh(y, values[:, i], left=np.sum(values[:, :i], axis=1), color=colors[i], label=f'Value {i+1}')
Customize
ax.set_yticks(y) ax.set_yticklabels([str(i) for i in y], fontsize=14) ax.set_xticks([0, 100]) # Set only 0 and 100 as x-axis ticks ax.set_xticklabels([0, 100], fontsize=15) # Increase font size for x-axis tick labels
ax.legend()
Adjust layout
plt.tight_layout()
Set y-axis limits to remove the space between x-axis and the first bar
ax.set_ylim(y[0] - 0.65, y[-1] + 0.65)
Show plot
Save the plot as a PNG image with a DPI of 300
plt.savefig('mixtral-impersonation-base-wahlomat', dpi=300) #plt.show()
As you can see, the x axis starts with 0 and ends with 37. I only want the following x-axis values on my plot: [9, 15, 18, 19, 25]
- Assistant
If you want your x-axis (which, in this case, because of the
barhfunction, acts more like a y-axis in terms of vertical orientation) to only display specific values such as [9, 15, 18, 19, 25], you will need to adjust the code where you set the y-tick labels and their positions. Remember that in your plot, due to using a horizontal bar plot (), what you're referring to as the "x-axis" with the values 0 to 37 are actually the y-tick labels, and thus should be set via the y-ticks in the Matplotlib API.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.