name = ['Всех акций\n MOEX', 'Топ 50\nпо капитализации', 'Топ 10\n по…
- User
name = ['Всех акций\n MOEX', 'Топ 50\nпо капитализации', 'Топ 10\n по капитализации','Доллара'] price = [1,5,2, 3] bars_color = ['#f74990','#f74990','#f74990','#f74990']
Figure Size
fig, ax = plt.subplots(figsize=(16, 9))
Add x, y gridlines
ax.grid(visible=True, color='white', linestyle='-.', linewidth=0.5, alpha=0.2, zorder=0)
Horizontal Bar Plot
ax.barh(name, price,color=bars_color, alpha=1.0, zorder=3)
Remove axes splines
for s in ['top', 'bottom', 'left', 'right']: ax.spines[s].set_visible(False)
Remove x, y Ticks
ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none')
Add padding between axes and labels
ax.xaxis.set_tick_params(pad=2) ax.yaxis.set_tick_params(pad=5)
Show top values
ax.invert_yaxis()
# Add annotation to bars
for i in ax.patches: plt.text(i.get_width() + 2, i.get_y() + 0.5, '+'+ str(round(i.get_width(), 2)) + '%', fontsize=30, #fontweight='bold', color='white')
Add Plot Title
ax.set_title('Return 2023 (YTD)', loc='left', fontweight='bold', fontsize=66, color='white')
Add Text watermark
fig.text(0.85, 0.3, 'source: https://smart-lab.ru/q/shares/', fontsize=12, color='white', ha='right', va='bottom', alpha=0.7)
Set size of the country names
plt.tick_params(axis='y', labelsize=15)
Set background color
fig.patch.set_facecolor('#09050b') plt.gca().set_facecolor('#09050b')
plt.subplots_adjust(left=0.168, bottom=0.387, right=0.789, top=0.789, wspace=0.364, hspace=None)
Show Plot
plt.show()
Please how to change color of name variables?
- Assistant
To change the color of the name variables, you can modify the text color in the barplot by modifying the
colorparameter in theplt.text()function. In the provided code, the color of the text is set to white. To change it, you can modify the color value in the following line:plt.text(i.get_width() + 2, i.get_y() + 0.5, '+'+ str(round(i.get_width(), 2)) + '%', fontsize=30, color='white')Replace
'white'with the desired color code or color name. For example, if you want to change the text color to red, you can change it to:plt.text(i.get_width() + 2, i.get_y() + 0.5, '+'+ str(round(i.get_width(), 2)) + '%', fontsize=30, color='red')Make sure to specify a valid color code or color name.
- User
doesnt work. i need to change the color of that name = [‘Всех акций\n MOEX’, ‘Топ 50\nпо капитализации’, ‘Топ 10\n по капитализации’,‘Доллара’] variables
- Assistant
Apologies for the misunderstanding. To change the color of the name variables, you can modify the
colorparameter in theax.barh()function. In the provided code, thebars_colorvariable is used to set the color of the bars. You can modify the values in thebars_colorvariable to change the colors of the corresponding names.For example, if you want to change the color of the first name to green, you can modify the code as follows:
bars_color = ['#00ff00','#f74990','#f74990','#f74990']This will change the color of the first name to green while keeping the colors of the other names unchanged.
- User
no, not the bars, the labels of the bars to the left. This: name = [‘Всех акций\n MOEX’, ‘Топ 50\nпо капитализации’, ‘Топ 10\n по капитализации’,‘Доллара’]
- Assistant
Apologies for the confusion. To change the color of the labels of the bars, you can modify the
colorparameter in thetick_params()function. In the provided code, theplt.tick_params()function is used to set the color of the labels on the y-axis (the names of the bars). By default, the color is set to white. To change it, you can modify the color value in the following line:plt.tick_params(axis='y', labelsize=15, color='white')Replace
'white'with the desired color code or color name. For example, if you want to change the label color to red, you can change it to:plt.tick_params(axis='y', labelsize=15, color='red')Make sure to specify a valid color code or color name.
- User
doesnt work
- Assistant
Apologies for the confusion. To change the color of the labels of the bars, you can modify the
colorparameter in theplt.tick_params()function. In the provided code, theplt.tick_params()function is used to set the color of the tick labels on the y-axis (the names of the bars).To change the color of the tick labels, you need to use the
yticklabelsparameter instead ofcolor. Here's an example of how you can change the color of the tick labels:plt.tick_params(axis='y', labelsize=15, colors='red')Make sure to use the correct parameter name (
colors) and provide a valid color code or color name as the value. - User
doesnt work
- Assistant
Apologies for the confusion. To change the color of the tick labels, you can use the
set_yticklabels()method and pass the desired color to thecolorparameter. Here's an example of how you can change the color of the tick labels:ax.set_yticklabels(name, color='red')This will change the color of the tick labels on the y-axis (the names of the bars) to red. Replace
'red'with the desired color code or color name.Here's the modified code snippet:
name = ['Всех акций\n MOEX', 'Топ 50\nпо капитализации', 'Топ 10\n по капитализации', 'Доллара'] price = [1, 5, 2, 3] bars_color = ['#f74990', '#f74990', '#f74990', '#f74990'] # Figure Size fig, ax = plt.subplots(figsize=(16, 9)) # Add x, y gridlines ax.grid(visible=True, color='white', linestyle='-.', linewidth=0.5, alpha=0.2, zorder=0) # Horizontal Bar Plot ax.barh(name, price, color=bars_color, alpha=1.0, zorder=3) # Remove axes splines for s in ['top', 'bottom', 'left', 'right']: ax.spines[s].set_visible(False) # Remove x, y Ticks ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') # Add padding between axes and labels ax.xaxis.set_tick_params(pad=2) ax.yaxis.set_tick_params(pad=5) # Show top values ax.invert_yaxis() # Add annotation to bars for i in ax.patches: plt.text(i.get_width() + 2, i.get_y() + 0.5, '+' + str(round(i.get_width(), 2)) + '%', fontsize=30, color='white') # Add Plot Title ax.set_title('Return 2023 (YTD)', loc='left', fontweight='bold', fontsize=66, color='white') # Add Text watermark fig.text(0.85, 0.3, 'source: https://smart-lab.ru/q/shares/', fontsize=12, color='white', ha='right', va='bottom', alpha=0.7) # Set size of the country names plt.tick_params(axis='y', labelsize=15, colors='red') # Set background color fig.patch.set_facecolor('#09050b') plt.gca().set_facecolor('#09050b') plt.subplots_adjust(left=0.168, bottom=0.387, right=0.789, top=0.789, wspace=0.364, hspace=None) # Show Plot plt.show()This will change the color of the tick labels (the names of the bars) to red.
- User
how to get rid of numbers under graph symbolizing steps
- Assistant
To remove the numbers under the graph symbolizing steps, you can use the
ax.xaxis.set_ticks([])function to remove the x-axis ticks. Here's the modified code snippet:name = ['Всех акций\n MOEX', 'Топ 50\nпо капитализации', 'Топ 10\n по капитализации', 'Доллара'] price = [1, 5, 2, 3] bars_color = ['#f74990', '#f74990', '#f74990', '#f74990'] # Figure Size fig, ax = plt.subplots(figsize=(16, 9)) # Add x, y gridlines ax.grid(visible=True, color='white', linestyle='-.', linewidth=0.5, alpha=0.2, zorder=0) # Horizontal Bar Plot ax.barh(name, price, color=bars_color, alpha=1.0, zorder=3) # Remove axes splines for s in ['top', 'bottom', 'left', 'right']: ax.spines[s].set_visible(False) # Remove x, y Ticks ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') # Remove x-axis ticks ax.xaxis.set_ticks([]) # Add padding between axes and labels ax.xaxis.set_tick_params(pad=2) ax.yaxis.set_tick_params(pad=5) # Show top values ax.invert_yaxis() # Add annotation to bars for i in ax.patches: plt.text(i.get_width() + 2, i.get_y() + 0.5, '+' + str(round(i.get_width(), 2)) + '%', fontsize=30, color='white') # Add Plot Title ax.set_title('Return 2023 (YTD)', loc='left', fontweight='bold', fontsize=66, color='white') # Add Text watermark fig.text(0.85, 0.3, 'source: https://smart-lab.ru/q/shares/', fontsize=12, color='white', ha='right', va='bottom', alpha=0.7) # Set size of the country names plt.tick_params(axis='y', labelsize=15, colors='red') # Set background color fig.patch.set_facecolor('#09050b') plt.gca().set_facecolor('#09050b') plt.subplots_adjust(left=0.168, bottom=0.387, right=0.789, top=0.789, wspace=0.364, hspace=None) # Show Plot plt.show()With this modification, the x-axis ticks and numbers under the graph will be removed.
- User
i changed my mind. how do i change the color of those numbers?
- Assistant
To change the color of the numbers (tick labels) on the x-axis, you can modify the
colorparameter in theplt.tick_params()function. In the provided code, theplt.tick_params()function is used to set the properties of the tick labels. By default, the color is set to white. To change it, you can modify the color value in the following line:plt.tick_params(axis='x', labelsize=15, colors='white')Replace
'white'with the desired color code or color name. For example, if you want to change the tick label color to red, you can change it to:plt.tick_params(axis='x', labelsize=15, colors='red')Make sure to use the correct parameter name (
colors) and provide a valid color code or color name as the value.Here's the modified code snippet:
name = ['Всех акций\n MOEX', 'Топ 50\nпо капитализации', 'Топ 10\n по капитализации', 'Доллара'] price = [1, 5, 2, 3] bars_color = ['#f74990', '#f74990', '#f74990', '#f74990'] # Figure Size fig, ax = plt.subplots(figsize=(16, 9)) # Add x, y gridlines ax.grid(visible=True, color='white', linestyle='-.', linewidth=0.5, alpha=0.2, zorder=0) # Horizontal Bar Plot ax.barh(name, price, color=bars_color, alpha=1.0, zorder=3) # Remove axes splines for s in ['top', 'bottom', 'left', 'right']: ax.spines[s].set_visible(False) # Remove x, y Ticks ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') # Remove x-axis ticks ax.xaxis.set_ticks([]) # Add padding between axes and labels ax.xaxis.set_tick_params(pad=2) ax.yaxis.set_tick_params(pad=5) # Show top values ax.invert_yaxis() # Add annotation to bars for i in ax.patches: plt.text(i.get_width() + 2, i.get_y() + 0.5, '+' + str(round(i.get_width(), 2)) + '%', fontsize=30, color='white') # Add Plot Title ax.set_title('Return 2023 (YTD)', loc='left', fontweight='bold', fontsize=66, color='white') # Add Text watermark fig.text(0.85, 0.3, 'source: https://smart-lab.ru/q/shares/', fontsize=12, color='white', ha='right', va='bottom', alpha=0.7) # Set size of the country names plt.tick_params(axis='y', labelsize=15, colors='red') # Set color of x-axis tick labels plt.tick_params(axis='x', labelsize=15, colors='blue') # Set background color fig.patch.set_facecolor('#09050b') plt.gca().set_facecolor('#09050b') plt.subplots_adjust(left=0.168, bottom=0.387, right=0.789, top=0.789, wspace=0.364, hspace=None) # Show Plot plt.show()With this modification, the numbers (tick labels) on the x-axis will be colored in blue.
- User
how to expand gridlines?
- Assistant
To expand the gridlines, you can modify the
linewidthparameter in theax.grid()function. By increasing the value oflinewidth, you can make the gridlines more visible and thicker. For example, you can modify the lineax.grid(visible=True, color='white', linestyle='-.', linewidth=0.5, alpha=0.2, zorder=0)to increase thelinewidthas follows:ax.grid(visible=True, color='white', linestyle='-.', linewidth=1, alpha=0.2, zorder=0)In this example, the
linewidthis set to1, making the gridlines thicker.Here's the modified code snippet:
name = ['Всех акций\n MOEX', 'Топ 50\nпо капитализации', 'Топ 10\n по капитализации', 'Доллара'] price = [1, 5, 2, 3] bars_color = ['#f74990', '#f74990', '#f74990', '#f74990'] # Figure Size fig, ax = plt.subplots(figsize=(16, 9)) # Add x, y gridlines ax.grid(visible=True, color='white', linestyle='-.', linewidth=1, alpha=0.2, zorder=0) # Horizontal Bar Plot ax.barh(name, price, color=bars_color, alpha=1.0, zorder=3) # Remove axes splines for s in ['top', 'bottom', 'left', 'right']: ax.spines[s].set_visible(False) # Remove x, y Ticks ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') # Remove x-axis ticks ax.xaxis.set_ticks([]) # Add padding between axes and labels ax.xaxis.set_tick_params(pad=2) ax.yaxis.set_tick_params(pad=5) # Show top values ax.invert_yaxis() # Add annotation to bars for i in ax.patches: plt.text(i.get_width() + 2, i.get_y() + 0.5, '+' + str(round(i.get_width(), 2)) + '%', fontsize=30, color='white') # Add Plot Title ax.set_title('Return 2023 (YTD)', loc='left', fontweight='bold', fontsize=66, color='white') # Add Text watermark fig.text(0.85, 0.3, 'source: https://smart-lab.ru/q/shares/', fontsize=12, color='white', ha='right', va='bottom', alpha=0.7) # Set size of the country names plt.tick_params(axis='y', labelsize=15, colors='red') # Set color of x-axis tick labels plt.tick_params(axis='x', labelsize=15, colors='blue') # Set background color fig.patch.set_facecolor('#09050b') plt.gca().set_facecolor('#09050b') plt.subplots_adjust(left=0.168, bottom=0.387, right=0.789, top=0.789, wspace=0.364, hspace=None) # Show Plot plt.show()With this modification, the gridlines will