我想更改轴的颜色,以及使用matplotlib和PyQt绘制的绘图的刻度和值标签.
有任何想法吗?
有没有办法在matplotlib中更改轴的颜色(而不是刻度线)?我一直在浏览Axes,Axis和Artist的文档,但没有运气; matplotlib画廊也没有提示.任何的想法?
我希望负条向下,正向上,x轴(0线)正好在它们之间.我试过这个
chart = fig.bar(x, negative_data, width=35, color='r')
ax2 = plt.gca().twinx()
ax2.bar(x, positive_data, width=35, color='b')
Run Code Online (Sandbox Code Playgroud)
但相反,我得到了合并的红色和白色条纹,两者都朝下.似乎数组negative_data/positive_data仅指定条的高度,但如何指定方向?我需要一些东西来指定每个条形顶部的坐标.
此外,如何使宽度合理,可能是动态的,因为图形由用户调整大小?
以下是有问题宽度的示例:
x = [250, 1500, 2750, 4250, 6000, 8500, 13200]
negative_data = [0, 0, 0, 0, 0, 0, 0]
positive_data = [3, 0, 0, 0, 1, 0, 0]
Run Code Online (Sandbox Code Playgroud)
我怎样才能让那些看起来很漂亮的情节?
我在Cartopy中绘制世界地图,作为整个过程的一部分,我想将所有线条涂成白色.除了地图的边界外,我已经能够为每个元素做到这一点.这是我正在使用的代码:
import matplotlib.pyplot as plt
import cartopy
import cartopy.io.shapereader as shpreader
import cartopy.crs as ccrs
fig = plt.Figure()
fig.set_canvas(plt.gcf().canvas)
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_feature(cartopy.feature.LAND, linewidth=0.5, edgecolor='white')
ax.set_extent([-150,60,-25,60])
shpf = shpreader.natural_earth(resolution='110m', category='cultural', name='admin_0_countries')
reader = shpreader.Reader(shpf)
countries = reader.records()
for country in countries:
ax.add_geometries(country.geometry, ccrs.PlateCarree(), facecolor=(0,1,0), linewidth=0.5, edgecolor='white', label=country.attributes['adm0_a3'])
fig.savefig("final_image.png", format='png', dpi=200)
Run Code Online (Sandbox Code Playgroud)
这是最终的结果:
想知道如何将边界线改为白色或完全关闭,尽可能少的步骤?
谢谢!
我想编写一个可调用的函数,为所有不同的图统一设置我的 matplotlib rc 参数。到目前为止,它只是我复制到每个文件的一个块,归结为:
import matplotlib as mpl
grey = '#808080'
mpl.rcParams['axes.linewidth'] = 0.3
mpl.rcParams['axes.edgecolor'] = grey
Run Code Online (Sandbox Code Playgroud)
我这样做是为了让轴更细,并通过让其他所有东西都变灰来突出我的数据。但是我找不到在 rc.local 中将刻度边缘颜色设置为灰色的方法。我正在寻找类似的东西
'axes.tickedgecolor'
Run Code Online (Sandbox Code Playgroud)
可悲的是,这似乎不存在。
这里描述了一种不使用 rc 的方法:Elegantly changed the color of a plot frame in matplotlib
希望有人能帮忙,谢谢!
编辑:只是为了澄清:我找到了选项
mpl.rcParams['tick.color'] = '#808080'
Run Code Online (Sandbox Code Playgroud)
但它也会改变刻度标签,我想保持黑色!