python怎么让图片旋转45度_是否有方法将matplotlib打印旋转45度?

基于按位anwer,可以使用以下函数:def pcolormesh_45deg(C, ax=None, xticks=None, xticklabels=None, yticks=None,

yticklabels=None, aspect='equal', rotation=45,

*args, **kwargs):

import itertools

if ax is None:

ax = plt.gca()

n = C.shape[0]

# create rotation/scaling matrix

t = np.array([[1, .5], [-1, .5]])

# create coordinate matrix and transform it

product = itertools.product(range(n, -1, -1), range(0, n + 1, 1))

A = np.dot(np.array([(ii[1], ii[0]) for ii in product]), t)

# plot

ax.pcolormesh((2 * A[:, 1].reshape(n + 1, n + 1) - n),

A[:, 0].reshape(n + 1, n + 1),

np.flipud(C), *args, **kwargs)

xticks = np.linspace(0, n - 1, n, dtype=int) if xticks is None else xticks

yticks = np.linspace(0, n - 1, n, dtype=int) if yticks is None else yticks

if xticks is not None:

xticklabels = xticks if xticklabels is None else xticklabels

for tick, label, in zip(xticks, xticklabels):

ax.scatter(-n + tick + .5, tick + .5, marker='x', color='k')

ax.text(-n + tick + .5, tick + .5, label,

horizontalalignment='right', rotation=-rotation)

if yticks is not None:

yticklabels = yticks if yticklabels is None else yticklabels

for tick, label, in zip(yticks, yticklabels):

ax.scatter(tick + .5, n - tick - .5, marker='x', color='k')

ax.text(tick + .5, n - tick - .5, label,

horizontalalignment='left', rotation=rotation)

if aspect:

ax.set_aspect(aspect)

ax.set_xlim(-n, n)

ax.set_ylim(-n, n)

ax.plot([-n, 0, n, 0., -n], [0, n, 0, -n, 0], color='k')

ax.axis('off')

return ax

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值