使用Python画一个带坐标轴的圆
Download Microsoft Visual Studio
Microsoft Visual Studio enables you develop your python Application, to use Microsoft Visual Studio developing your application, first thing is to install Visual Studio.
Download Microsoft Visual Studio online, download Visual Studio .
Choose Python when installing Microsoft Visual Studio

After installation complete, launch the Visual Studio and create a project.
- Select File > New > Project
- In the New Project window, expand Installed, expand Python.
- In the template, select Python Application.
- Choose your Name and Location, then click OK.
Install matplotlib and numpy package
- Select View > Ohter Windows > Python Environments.
- In the right side of window, switch to Python Environment (In same window to the Solution Explorer).
- Select one version, for example, Python 3.6. Select Packages.
- In the search box, type matplotlib and select “pip install matplotlib” from PyPI.
- Wait for the installation complete.
- Repeat above two steps for numpy.
Open python file, write code to plot a circle step by step
The equation for a circle is
x^2 + y^2 = 1, therefore,y = +sqrt(1-x^2)andy = -sqrt(1-x^2).
- Select Soltuion Explorer, double click on the python file to open it, in my side, the file name is PythonApplication1.py.
- Import pyplot and numpy libraries.
import matplotlib.pyplot as plt
import numpy as np
- Define a Figure window with name Figure1 and size as width=5, height=5.
plt.figure(num=1,figsize=(5,5))
- Use
numpy.linspaceto define x with some points, starting from -1 to 1, randomly generate 500 points. - Use
numpy.sqrtto define the corresponding y1 and y2.
x = np.linspace(-1, 1, 500)
y1 = np.sqrt(1-x**2)
y2 = -np.sqrt(1-x**2)
- Plot the figure and show the figure
l1, = plt.plot(x, y1, color='blue')
l2, = plt.plot(x, y2, color='blue')
... plt.show()
- Here is what you get so far:

Customize your Figure
(NOTE: all the code need be added before the line of plt.show())
- Then, you can customize the steps and points in the x axis and y axis, the functions are
pyplot.xticksandpyplot.yticks. - In following code, I defined some numbers by using
numpy.arange(), the numbers are -1, -0.5, 0, 0.5, 1. Use these numbers both for x axis and y axis.
new_ticks = np.arange(-1,1,0.5)
plt.xticks(new_ticks)
plt.yticks(new_ticks)
- If you want to customize the border and axis location, you can use
plt.gca(), the following code did three things:- Set the position of y axis to -1.
- Set the postion of x axis to -1.
- Remove the border of right edge.
- Remove the border of top edge.
ax = plt.gca()
ax.spines['left'].set_position(('data',-1))
ax.spines['bottom'].set_position(('data',-1))
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
- Now here is what you get:

- If you want to move the axis to 0, then just change the value from -1 to 0 in above code.
ax.spines['left'].set_position(('data',0))
ax.spines['bottom'].set_position(('data',0))
- Add a legend to the upper right corner, the string inside the
'should sround with$, and it will render better acording to what support best by the system.
plt.legend(handles=[l1,l2,], labels=[r'$x^2+y^2=1$'], loc='upper right')
- Add axes at the end of the axis by using
plt.annotate().
plt.annotate('$x$', xy=(0.98,0.5), ha='left', va='top', xycoords='axes fraction', fontsize=20)
plt.annotate('$y$', xy=(0.5,1), ha='left', va='top', xycoords='axes fraction', textcoords='offset points',fontsize=20)
- This is what you get finall, pretty cool.

使用Python画一个带坐标轴的圆的更多相关文章
- 用CSS画一个带阴影的三角形的示例代码
1. 思路 怎么用CSS3画一个带阴影的三角形呢 ? 有童鞋说, 这还不简单吗 网上有很多解决方案, 但其实大多都是实现不太完美的, 存在一些问题 假设我们做一个向下的三角形箭头 常见的方法大致有两种 ...
- Directx11教程(10) 画一个简易坐标轴
原文:Directx11教程(10) 画一个简易坐标轴 本篇教程中,我们将在三维场景中,画一个简易的坐标轴,分别用红.绿.蓝三种颜色表示x,y,z轴的正向坐标轴. 为此,我们要先建立一个A ...
- D3.js(v3)+react 制作 一个带坐标轴与比例尺的折线图
本章使用路径生成器来绘制一个折线图.以中国和日本的GDP数据为例: //数据 var dataList = [ { coountry : "china", gdp : [ [2 ...
- 【 D3.js 入门系列 --- 5.1 】 做一个带坐标轴和标签的图表
前面几节讲解了图标.坐标轴.比例等等,这一节整合这些内容做一个实用的图表.结果图如下: 代码如下所示: <html> <head> <meta charset=" ...
- Python画一个四点连线并计算首尾距离
import turtle import math #先定义4个坐标 x1,y1=100,100 x2,y2=100,-100 x3,y3=-100,-100 x4,y4=-100,100 #然后 ...
- 新学python画一个爱心
from turtle import * def curvemove(): for i in range(200): right(1) forward(1) color('yellow','red') ...
- 如何用Python画一个圣诞树呢?
# ./sd.py * *** ***** ******* ********* |[root@bogon shengdan]# vim sd.py[root@bogon shengdan]# cat ...
- 用Python画一个八角形代码示例
import turtle turtle.color("purple","yellow") turtle.speed(1) turtle.fd(100) t ...
- 用PS画一个齿轮
以前只会画圆画方,这没技术含量.今天学了一个稍难一点的,画一个齿轮.图形有圆也有方.以下描述如何画出来的. 一.打开PS准备一画布,画一矩形并且填充颜色. 二.编辑->自由变换(CTRL+T), ...
随机推荐
- javascript高级程序设计第3版——第8章 BOM(浏览器对象模型)
第八章,浏览器对象模型 主要介绍了window的几个对象以及框架,窗口的关系,各个浏览器对象的属性以及方法:
- nvm 设置 nodejs 默认版本
nvm 设置 nodejs 默认版本 windows 系统的版本管理软件是nodist mac系统的node版本管理根据是nvm 每次重启vscode软件后,nvm ls 看到的默认版本都会恢复到v5 ...
- hive -- 自定义函数和Transform
hive -- 自定义函数和Transform UDF操作单行数据, UDAF:聚合函数,接受多行数据,并产生一个输出数据行 UDTF:操作单个数据 使用udf方法: 第一种: add jar xxx ...
- 洛谷1855 榨取kkksc03
题目描述 洛谷2的团队功能是其他任何oj和工具难以达到的.借助洛谷强大的服务器资源,任何学校都可以在洛谷上零成本的搭建oj并高效率的完成训练计划. 为什么说是搭建oj呢?为什么高效呢? 因为,你可以上 ...
- SSM框架中如何简便上传文件表单
此种方式上传文件相对简单,以下均经测试成功,才提供到此. 以下为单个文件上传方式 分析:本次的工作目的是根据一级标题产生对应的二级标题,在每个二级标题下对应一个(file字段)新闻文件,当点击新闻文件 ...
- 在Postman中使用不受信任的SSL证书
阅读目录 第一种方案——临时添加到受信任的证书颁发机构: 第二种方案——永久添加到受信任的证书颁发机构: add by zhj: 在http://www.cnblogs.com/ajianbeyour ...
- 常用adb 指令
adb指令 monkey https://www.cnblogs.com/aland-1415/p/6949964.html
- git 工作区管理
git工作区 git的工作区就是电脑中能看到的目录,比如我的learning文件夹就是一个工作区 版本库暂存区 工作去有一个隐藏的目录.git,这个不算工作区,而是git的版本库 git的版本库中存了 ...
- MySQL · 性能优化· 5.7.6 InnoDB page flush 优化
在这篇文中,我们已经详细介绍了Oracle MySQL以及社区分支最新的对InnoDB page flush的优化.在最近release的5.7.6版本中又有了进一步的改进.主要包括以下几点修改 修改 ...
- conda的使用(附带远程文件传输命令)
1 环境管理 1.1查看当前系统下的环境 conda info -e 创建新的环境 # 指定python版本为3.6,注意至少需要指定python版本或者要安装的包 conda create -n m ...