我正在尝试使用具有不连续x轴的pyplot创建一个图。通常的绘制方法是轴将具有以下内容:
(值)---- // ----(后值)
// //表示您正在跳过(值)和(后值)之间的所有内容。
我还没有找到任何这样的例子,所以我想知道是否有可能。我知道您可以在不连续的情况下加入数据,例如财务数据,但我想使轴上的跳跃更明确。目前,我只是在使用子图,但我真的很希望最终所有内容都在同一张图上。
这只是此示例的简单修改,具有不连续的x轴而不是y轴。(这就是为什么我要将此帖子设为CW)
基本上,你只需要执行以下操作:
import matplotlib.pylab as plt
import numpy as np
# If you're not familiar with np.r_, don't worry too much about this. It's just
# a series with points from 0 to 1 spaced at 0.1, and 9 to 10 with the same spacing.
x = np.r_[0:1:0.1, 9:10:0.1]
y = np.sin(x)
fig,(ax,ax2) = plt.subplots(1, 2, sharey=True)
# plot the same data on both axes
ax.plot(x, y, 'bo')
ax2.plot(x, y, 'bo')
# zoom-in / limit the view to different portions of the data
ax.set_xlim(0,1) # most of the data
ax2.set_xlim(9,10) # outliers only
# hide the spines between ax and ax2
ax.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax.yaxis.tick_left()
ax.tick_params(labeltop='off') # don't put tick labels at the top
ax2.yaxis.tick_right()
# Make the spacing between the two axes a bit smaller
plt.subplots_adjust(wspace=0.15)
plt.show()
要添加折断的轴线//效果,我们可以这样做(同样,从Paul Ivanov的示例进行了修改):
import matplotlib.pylab as plt
import numpy as np
# If you're not familiar with np.r_, don't worry too much about this. It's just
# a series with points from 0 to 1 spaced at 0.1, and 9 to 10 with the same spacing.
x = np.r_[0:1:0.1, 9:10:0.1]
y = np.sin(x)
fig,(ax,ax2) = plt.subplots(1, 2, sharey=True)
# plot the same data on both axes
ax.plot(x, y, 'bo')
ax2.plot(x, y, 'bo')
# zoom-in / limit the view to different portions of the data
ax.set_xlim(0,1) # most of the data
ax2.set_xlim(9,10) # outliers only
# hide the spines between ax and ax2
ax.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax.yaxis.tick_left()
ax.tick_params(labeltop='off') # don't put tick labels at the top
ax2.yaxis.tick_right()
# Make the spacing between the two axes a bit smaller
plt.subplots_adjust(wspace=0.15)
# This looks pretty good, and was fairly painless, but you can get that
# cut-out diagonal lines look with just a bit more work. The important
# thing to know here is that in axes coordinates, which are always
# between 0-1, spine endpoints are at these locations (0,0), (0,1),
# (1,0), and (1,1). Thus, we just need to put the diagonals in the
# appropriate corners of each of our axes, and so long as we use the
# right transform and disable clipping.
d = .015 # how big to make the diagonal lines in axes coordinates
# arguments to pass plot, just so we don't keep repeating them
kwargs = dict(transform=ax.transAxes, color='k', clip_on=False)
ax.plot((1-d,1+d),(-d,+d), **kwargs) # top-left diagonal
ax.plot((1-d,1+d),(1-d,1+d), **kwargs) # bottom-left diagonal
kwargs.update(transform=ax2.transAxes) # switch to the bottom axes
ax2.plot((-d,d),(-d,+d), **kwargs) # top-right diagonal
ax2.plot((-d,d),(1-d,1+d), **kwargs) # bottom-right diagonal
# What's cool about this is that now if we vary the distance between
# ax and ax2 via f.subplots_adjust(hspace=...) or plt.subplot_tool(),
# the diagonal lines will move accordingly, and stay right at the tips
# of the spines they are 'breaking'
plt.show()
问题内容: 在Python解释器中执行以下指令后,将获得一个带有绘图的窗口: 不幸的是,当程序进行进一步的计算时,我不知道如何继续以交互方式探索创建的图形。 有可能吗?有时计算很长,如果可以在检查中间结果时进行计算,则将有所帮助。 问题答案: 使用不会阻塞的呼叫: 使用: 使用交互模式:
问题内容: 在Python解释器中执行了这些指令后,将获得一个带有绘图的窗口: 不幸的是,当程序进行进一步的计算时,我不知道如何继续以交互方式探索创建的图形。 有可能吗?有时计算很长,如果可以在检查中间结果时进行计算,则将有所帮助。 问题答案: 使用不会阻塞的呼叫: 使用: 使用交互模式:
我正在创建从URL加载顺序mp3文件的应用程序。当我尝试在完成第一个mp3文件时初始化下一个mp3文件,但问题是,当第一个文件完成时,播放器需要时间来准备或初始化下一个mp3文件,是的,我知道这是媒体播放器的一部分,它需要时间准备(对于它可能很长,对于相对排序时间)。 但是,我需要的是,当第一个mp3文件完成播放时,下一个mp3文件(来自url)不应该花费时间来准备,因为它应该在不中断的情况下播放
我有下一个树状图代码 而这个输出 如何更改每个子情节的大小?
问题内容: 我想在Python中使用PhantomJS。我用谷歌搜索了这个问题,但是找不到合适的解决方案。 我发现 可能是一个不错的选择。但是我无法通过一些争论。 使用可能是目前合适的解决方案。我想知道是否有更好的解决方案。 有没有办法在Python中使用PhantomJS? 问题答案: 在python中使用PhantomJS的最简单方法是通过Selenium。最简单的安装方法是 安装NodeJS
问题内容: 我们正在开发S60版本,该平台具有不错的Python API。 但是,关于Android上的Python尚无任何官方资料,但是由于Jython存在,有没有办法让蛇和机器人一起工作? 问题答案: 一种方法是使用: 开源Python库,用于快速开发利用创新用户界面的应用程序,例如多点触控应用程序。 可在和上运行。你可以在所有受支持的平台上运行相同的代码。