Python Matplotlib: change dashboard width dashboard

I am trying to edit the line width that appears in my color bar separately from the contour line lines that I draw in Matplotlib. I would like to set the width of the outline lines to 0.5, but when I do this, I don't see the color outlines in the color bar. If I set the outline line width to 1.5, I can see them in the color bar, but the outlines are too thick for me. plots of each case

import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import numpy as np

#get data
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = 10.0 * (Z2 - Z1)
#get contour levels
levels=[-1.5,-1.25,-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1,1.25,1.5]
fig = plt.figure()
ax = fig.add_subplot(111)
#plot contours and color bar
CS = plt.contour(X,Y,Z,levels, linestyles='solid', linewidths=0.5, extent=(-3,3,-3,3))  
plt.clabel(CS, colors='black', inline=True, inline_spacing=0, fontsize=8)
CB = plt.colorbar(CS, aspect=35, shrink=0.5, pad=0.09, orientation='horizontal', extend='both')
CB.set_ticks(levels)
CB.set_label('(values)',size=8)
CB.ax.tick_params(labelsize=6) 
#set plot limits
plt.xlim([-3,3])
plt.ylim([-3,3])
#set aspect ratios to be equal
plt.axes().set_aspect('equal')
#set ticks of plot
ax.xaxis.set_major_locator(plt.MultipleLocator(1.0))
ax.yaxis.set_major_locator(plt.MultipleLocator(1.0))
plt.xticks(fontsize=8)
plt.yticks(fontsize=8)

plt.show()

Any ideas on how I can separately control the width of the contour lines and the width of the colorbar lines?

+4
source share
1 answer

Use the line width you want for CS (e.g. 0.5). Then add this line:

CB.lines[0].set_linewidth(10)

.
, , , , linewithds.

+2

All Articles