Created
March 26, 2023 21:37
-
-
Save atodev/21f17c3a482d71e807e9b78dccd597cd to your computer and use it in GitHub Desktop.
[Plots]
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 matplotlib.pyplot as plt | |
# Define the color scheme based on the values | |
colors = ['red' if x < 15 else 'Yellow' if x >= 15 and x < 25 else 'green' for x in df1['TrustScore']] | |
# Create the bar chart with the defined colors | |
plt.bar(range(len(df1)), df1['TrustScore'], color=colors) | |
# Add labels and titles to the chart | |
plt.xticks(range(len(df1)), df1.index) | |
plt.xlabel('Index') | |
plt.ylabel('TrustScore') | |
plt.title('Trust Score overall') | |
# Define the legend | |
legend_dict = {'red': 'Weak', 'Yellow': 'Medium', 'green': 'Strong'} | |
legend_labels = [legend_dict[color] for color in colors] | |
plt.legend(labels=legend_labels) | |
plt.show() | |
------------------------------ | |
# Define a function to map TrustScore values to colors | |
def color_map(x): | |
if x < 15: | |
return 'red' | |
elif x < 25: | |
return 'yellow' | |
else: | |
return 'green' | |
# Create a new column using the color_map function | |
df1['TrustScoreColor'] = df1['TrustScore'].apply(color_map) | |
--- | |
import matplotlib.pyplot as plt | |
# Create the bar chart with color coding based on the new column | |
plt.bar(range(len(df1)), df1['TrustScore'], color=df1['TrustScoreColor']) | |
# Add labels and titles to the chart | |
plt.xticks(range(len(df1)), df1.index) | |
plt.xlabel('Index') | |
plt.ylabel('TrustScore') | |
plt.title('Trust Score overall') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment