Matlab转Python 画图pcolormesh的使用及一些注意事项

这篇具有很好参考价值的文章主要介绍了Matlab转Python 画图pcolormesh的使用及一些注意事项。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

今天想把matlab一段画图代码转为python,使用到了colormap,尝试了一下午,将结果以及一些注意事项记录下来,算作学习笔记了。

先上matlab原代码

a = 0.13; b = 0.12; 
c = 0.7; d = 0.8;

figure( 'Position', [200 50 1100 900], 'InvertHardcopy', 'off', 'Color', 'w' ); 
colormap( jet(512) );
han = axes( 'Units', 'normalized', 'Position', [a b c d],...
            'Xlim', [timee(1), timee(timedim)],... 
            'YLim', [-30, 20], 'Ydir', 'reverse',...
            'FontName', 'Times', 'FontSize', 24, 'FontWeight', 'bold', 'Layer', 'top','LineWidth',1.5);


hold on;
xlabel( 'Time (ps)', 'FontName', 'Times', 'FontWeight', 'bold', 'FontSize', 32);
ylabel( 'Position (nm)', 'FontName', 'Times', 'FontWeight', 'bold', 'FontSize', 32); 
text( 0.10, 0.90, sprintf( '%5.0f ps', 10), 'Units', 'normalized','HorizontalAlignment', 'center', 'FontName', 'Times', 'FontSize', 50, 'FontWeight', 'bold', 'Color', 'r' );

set(colorbar, 'Position', [0.89 0.12 0.02 0.78], 'FontName', 'Times',...
  'FontSize', 24, 'FontWeight', 'bold' );
caxis([300 9500])   
% 'Dirction', 'reverse'
hold on;

pcolor(timee, pos, Data');
shading interp;
hold on;  

text( 1.04, 0.5, 'Temperature (K)', 'Units', 'normalized', 'Rotation', 90, 'HorizontalAlignment', 'center', ...
    'FontName', 'Times', 'FontSize', 32, 'FontWeight', 'bold', 'Color', 'k' );

结果如下:


fig, ax = plt.subplots(figsize=(15, 10))
c = ax.pcolormesh(timee, pos, Data.T, cmap='jet', vmin=1000, vmax=9000, shading='gouraud')
ax.set_xlim(timee[0], timee[timedim-1])
ax.set_ylim(-30, 20)

c_ = fig.colorbar(c, ax=ax)
c_.ax.tick_params(labelsize=32)  # 设置colorbar的标签字体及其大小
ax.set_xticklabels(ax.get_xticks(), size=30)
ax.set_yticklabels(ax.get_yticks(), size=30)

ax.set_xlabel('Time (ps)', family='Times', weight='bold', fontsize=32)
ax.set_ylabel('Position (nm)', family='Times', weight='bold', fontsize=32)

ax.invert_yaxis()

ax.text(51.5, 4.5, 'Temperature (K)', rotation=90, horizontalalignment='center',
        family='Times', fontsize=25, weight='bold', color='k')
ax.text(7, -25, '10 ps', horizontalalignment='center',
        family='Times', fontsize=50, weight='bold', color='r')

plt.show()

注意:

在pcolormesh函数使用过后,就必须要设置xlim或者ylim,然后再使用colorbar的函数,否则设置ylim会导致语句无效,不会报错但是改不了。想让图像更平滑一些,就加这个参数shading='gouraud'

可以参考下面的网站,熟悉axes的用法。

axes相关属性设置

pcolormesh的参数

Parameters:

C : array_like

A scalar 2-D array. The values will be color-mapped.

X, Y : array_like, optional

cmap : str or Colormap, optional

A Colormap instance or registered colormap name. The colormap maps the C values to colors. Defaults to rcParams["image.cmap"].

norm : Normalize, optional

The Normalize instance scales the data values to the canonical colormap range [0, 1] for mapping to colors. By default, the data range is mapped to the colorbar range using linear scaling.

Normalize实例将数据值缩放到用于映射到颜色的规范化colormap范围[0,1]。默认情况下,使用线性缩放将数据范围映射到colorbar范围。

vmin, vmax : scalar, optional, default: None

The colorbar range. If None, suitable min/max values are automatically chosen by the Normalizeinstance (defaults to  the respective min/max values of C in case of the default linear scaling).

edgecolors : {'none', None, 'face', color, color sequence}, optional

  边缘颜色,默认None:

  • 'none' or '': No edge.
  • nonrcParams["patch.edgecolor"] will be used. Note that currentlyrcParams["patch.force_edgecolor"] has to be True for this to work.
  • 'face': Use the adjacent face color.
  • An mpl color or sequence of colors will set the edge color.

The singular form edgecolor works as an alias.

alpha : scalar, optional, default: None

  透明度

shading : {'flat', 'gouraud'}, optional

The fill style, Possible values:

  填充式样

  • 'flat': A solid color is used for each quad. The color of the quad (i, j), (i+1, j), (i, j+1), (i+1, j+1) is given by C[i,j].
  • 'gouraud': Each quad will be Gouraud shaded: The color of the corners (i', j') are given by C[i',j']. The color values of the area in between is interpolated from the corner values. When Gouraud shading is used, edgecolors is ignored.

snap : bool, optional, default: False

Whether to snap the mesh to pixel boundaries文章来源地址https://www.toymoban.com/news/detail-456005.html

到了这里,关于Matlab转Python 画图pcolormesh的使用及一些注意事项的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • ES 一些简单 的查询注意事项

    term query 不分词字段 带分数 where name=xxx filter 分词字段 不分词字段 不带分数 Terms query 所有类型 带分数 where name in(xxx) Range query where name between xxx and xxx Exists Regexp Match query 分词字段/基础字段 Multi-match query 多个分词字段/基础字段 Boolean query 复合查询 must should 带分数 filter must

    2024年02月12日
    浏览(71)
  • Elasticsearch 一些异常报错、注意事项(1)

    系统支持通过参数(op_type=create)强制执行创建索引操作。只有当系统中不存在此文档的时候才会创建成功。如果不指定此操作类型,如果存在此文档则会进行更新操作。 bulk 默认op_type 是index 当创建文档的时候,如果不指定id,系统则会默认创建id。自动生成的id是一个不会重

    2023年04月08日
    浏览(20)
  • 手机怎么剪视频?分享一些剪辑工具和注意事项

    视频剪辑是一种将多个视频片段进行剪切、合并和编辑的技术,它可以帮助我们制作出精彩的视频作品。如今,随着智能手机的普及,我们可以随时随地使用手机进行视频剪辑。本文将为大家介绍一些手机剪辑工具和注意事项,帮助大家更好地进行视频剪辑。   首先,我们来

    2024年02月10日
    浏览(36)
  • Spring Data Elasticsearch 一些异常报错、注意事项(1)

    记录一:批量更新数据saveAll 引入maven依赖  saveAll批量新增,如果数据存在则会更新数据 记录二:批量更新数据Script脚本更新字段 参考:Script query | Elasticsearch Guide [8.5] | Elastic 记录三:空字段查询处理 如果查询字段createTime在ES数据中不存在,直接用.must(QueryBuilders.rangeQuery(

    2024年02月11日
    浏览(34)
  • Unity发布抖音小游戏的一些注意事项

    使用 webgl模式 发布抖音小游戏的一些注意事项 1.打包 使用webgl模式打包抖音小游戏,会因为找不到aapt工具导致打包失败 提示: aapt检查失败: sdk/build-tools/版本号。 解决方法:再unity hub里添加Android Build Support  2.黑屏问题 相机的HDR设为off 3.Text字体不见的问题 不能用unity自带的

    2024年02月11日
    浏览(30)
  • git常规操作流程(纯命令行操作)和一些注意事项

    当你在单位拿到了git仓库,并利用公司给你的OA账号和邮箱完成了你的git基础配置,下面就是使用命令行的无错固定操作流程 如果你很着急,你可以直接跳到最后的 总结部分 1.从仓库克隆代码到本地 这里的[codeUrl]就是你仓库的地址,当你在仓库点击图中绿色位置时,剪贴板复制的就

    2024年02月03日
    浏览(30)
  • 关于 Go 协同程序(Coroutines 协程)、Go 汇编及一些注意事项。

    参考:  Go 汇编函数 - Go 语言高级编程 Go 嵌套汇编 - 掘金 (juejin.cn) 前言: Golang 适用 Go-Runtime(Go 运行时,嵌入在被编译的PE可执行文件之中)来管理调度协同程式的运行。 Go 语言没有多线程(MT)的概念,在 Go 语言之中,每个 Go 协程就类似开辟了一个新的线程,效率上,肯

    2024年01月25日
    浏览(59)
  • MySQL5 和 MySQL8 的配置区别 & 一些注意事项

    先保证你的mysql正在运行,假如用户名是 root ,密码是 123456 ,运行下边的代码可以查看mysql的版本号。 这里我的版本是5.7.19。也就是5版本的。 注意:下边的url区别不用管。看到这就可以了。 当然8版本的后边不写也没事。 不建议在没有服务器身份验证的情况下建立SSL连接。

    2024年02月05日
    浏览(28)
  • MATLAB 并行计算 parfor 用法及注意事项

    最近在用MATLAB做工作空间计算,for循环次数较多,运算非常慢,同学说可以使用并行计算,于是尝试,大开眼界。 参考文章:Matlab并行计算(新手)_a99h的博客-CSDN博客 在较新版本的matlab中,不需要使用p=parpool(n)来手动开启线程池,操作变得更简单。 (注:MATLAB 2023a已经不需

    2024年02月10日
    浏览(23)
  • 使用pycharm入门python的一些注意点

    今儿在帮别人跑一段python代码,实际上我对python并不熟悉,只能边摸索边尝试。选择了pycharm这个工具。 能用来安装python的库文件的,有很多种办法,这里只介绍pip和pip3。因为pip和pip3的优势是能自行解决依赖问题。 1. 搞清楚pip和pip3的区别 网上能搜到的pip和pip3的区别,都是

    2024年02月09日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包