从ISO-8859-1到UTF-8的PHP编码(PHP encoding from ISO-8859-1 to UTF-8)
<?php mb_internal_encoding('UTF-8'); mb_language('uni'); $a=file_get_contents("http://www.ciao.de/Erfahrungsberichte/8x4_Wild_Flower_Deo_Spray__8937431"); preg_match('/dass auf dem Versch(.*)ziehen mich/Us',$a,$b); $b=$b[1]; echo $b."\n"; echo utf8_encode($b)."\n"; echo mb_convert_encoding($b,'UTF-8','iso-8859-1')."\n";
结果是
lussdeckel riesengro▒ und un▒bersehbar glitzernd ein ▒New▒ prangt. Neue Produkte lussdeckel riesengroß und unübersehbar glitzernd ein �New� prangt. Neue Produkte lussdeckel riesengroß und unübersehbar glitzernd ein �New� prangt. Neue Produkte
HTTP源代码在meta标签中建议使用“iso-8859-1”。 德语变音符号很好,但为什么“New”引号没有正确转换? 在PHP 手册中有一个函数fix_latin。 使用此功能时,引号也可以正确转换!
PS:与欧洲货币符号€(EUR)相同 - 它也被错误地转换(除了使用fix_latin函数),但为什么?
<?php mb_internal_encoding('UTF-8'); mb_language('uni'); $a=file_get_contents("http://www.ciao.de/Erfahrungsberichte/8x4_Wild_Flower_Deo_Spray__8937431"); preg_match('/dass auf dem Versch(.*)ziehen mich/Us',$a,$b); $b=$b[1]; echo $b."\n"; echo utf8_encode($b)."\n"; echo mb_convert_encoding($b,'UTF-8','iso-8859-1')."\n";
results in
lussdeckel riesengro▒ und un▒bersehbar glitzernd ein ▒New▒ prangt. Neue Produkte lussdeckel riesengroß und unübersehbar glitzernd ein �New� prangt. Neue Produkte lussdeckel riesengroß und unübersehbar glitzernd ein �New� prangt. Neue Produkte
HTTP source code suggests in meta tag to use "iso-8859-1". German umlauts are fine, but why are the quotes around "New" not converted correctly? In PHP manual there is a function fix_latin. When using this function the quotes are also converted correctly!?
PS: same occurs with european currency symbol € (EUR) - it's also converted wrong (except with the fix_latin function), but why?
原文:https://stackoverflow.com/questions/6489268
最满意答案
这是一个解决方案。 在主窗口小部件内部绘制一个绘图小部件,似乎可以工作,并且可以使用setGeometry控制位置。
self.main_widget = QtGui.QWidget(self) self.plot_widget = QtGui.QWidget(self.main_widget) self.plot_widget.setGeometry(250,180,500,600) self.figure = plt.figure() self.plotting = FigureCanvas(self.figure) self.plot() plot_box = QtGui.QVBoxLayout() plot_box.addWidget(self.plotting) self.plot_widget.setLayout(plot_box)
Here is a solution. Make a plot widget inside of the main widget, seems to work and can control position with setGeometry.
self.main_widget = QtGui.QWidget(self) self.plot_widget = QtGui.QWidget(self.main_widget) self.plot_widget.setGeometry(250,180,500,600) self.figure = plt.figure() self.plotting = FigureCanvas(self.figure) self.plot() plot_box = QtGui.QVBoxLayout() plot_box.addWidget(self.plotting) self.plot_widget.setLayout(plot_box)
相关问答
更多-
PyQt5和Matplotlib 1.4.2 - 安装一个打破另一个(PyQt5 and Matplotlib 1.4.2 - installing one breaks the other)[2023-05-10]
由于你的matplotlib依赖于PyQt4,你需要强制Matplotlib使用PyQt5后端。 喜欢这个: import matplotlib matplotlib.use("Qt5Agg") 这个函数必须在第一次导入pyplot 之前调用; 或者,如果您不使用pyplot,则必须在导入matplotlib.backends之前调用它。 As your matplotlib depends on PyQt4, you need to force Matplotlib to use PyQt5 backe ... -
实际上并不复杂 相关的Qt小部件在matplotlib.backends.backend_qt4agg 。 FigureCanvasQTAgg和NavigationToolbar2QT通常是您需要的。 这些是常规的Qt小部件。 你把它们视为任何其他小部件。 下面是一个非常简单的例子,其中包括Figure , Navigation和单个按钮,可以绘制一些随机数据。 我已经添加了评论来解释事情。 import sys from PyQt4 import QtGui from matplotlib.backen ...
-
您还可以在链接到的问题中看到, FuncAnimation需要一个方法作为其第二个参数。 但是在你的调用中你提供了None (因为self.animate_loop()计算结果为None )。 将此更改为 self.anim = animation.FuncAnimation(fig, self.animate_loop, interval=optimal_frequency) 其次,从链接的问题也可以看出, self.animate_loop需要进行参数,所以你可能需要将此更改为 def animate ...
-
这是一个解决方案。 在主窗口小部件内部绘制一个绘图小部件,似乎可以工作,并且可以使用setGeometry控制位置。 self.main_widget = QtGui.QWidget(self) self.plot_widget = QtGui.QWidget(self.main_widget) self.plot_widget.setGeometry(250,180,500,600) self.figure = plt.figure() self.plotting = FigureCanvas(self. ...
-
python pyqt matplotlib计算GUI应用程序绘图错误(python pyqt matplotlib computation GUI app plotting wrong)[2023-10-13]
我的猜测是你使用Python-2,其中/运算符对于整数的行为与浮点的行为不同。 在第一种情况下,它是一个整数除法:结果是一个整数,其余部分被丢弃。 在第二种情况下,这是您通常期望从部门得到的结果。 这是很多错误的来源,所以在Python-3中, /运算符总是一个常规分区(返回一个浮点数),整数除法可以用//完成。 欲了解更多详情,请参阅PEP-238 。 请注意,您的calSaturationCurrent函数包含这样一个整数除法: 1/Tc在Python-2中产生0。 为了使Python-2的行为像Pyt ... -
您在matplotlib发现了一个有趣的错误。 Qt4后端不会清除重绘前用于显示图形的qImage ,因此您可以看到阴影的原因。 这可以通过向matplotlib.backends.backed_qt4Agg.FigureCanvasQTAgg.paintEvent添加几行来轻松解决。 def paintEvent(self, e): """ Copy the image from the Agg canvas to the qt.drawable. In Qt, all drawi ...
-
嘿,我搜索了解决方案,但找不到任何好的提示。 但后来我试着用代码玩一点。 不知何故它现在有效(问题是线ax.hold(假): 如果您这样称呼它(来自您的问题的代码): data = [{'med': 6.0, 'q1': 4.0, 'q3': 8.0, 'whislo': 3.0, 'whishi': 10.0, 'fliers': [20, 1]}] ax = self.figure.add_subplot(111) ax.hold(False) // call hold BEFORE bxp(data) ...
-
感谢@ImportanceOfBeingErnest(请参阅问题下面的评论),我自己想清楚了。 任何人偶然发现这个问题的答案都是这样。 如果你想在matplotlib中使用PyQt5在个人窗口中创建图形,那么对于大多数人来说,这种方法就是运行matplotlib.use('Qt5Agg')然后是%matplotlib qt5 。 由于某些原因,我仍然不知道这对我来说不起作用。 但是,解决方法是检查以下两个文件:/. /.ipython/ipython_config.py和/.ipython/ipython_ ...
-
我不清楚你是否想使用PySide或PyQt ,但在任何一种情况下问题是你想使用一个,但是matplotlib正在使用另一个设置Qt4后端,因此看起来令人困惑的错误。 如果你想使用PySide确认 backend.qt4 : PySide # PyQt4 | PySide 在你的matplotlibrc文件中。 如果你想使用PyQt确认 backend.qt4 : PyQt4 # PyQt4 | PySide 在你的matplotlibrc文件中。 I am not clear ...
-
我需要使用MatPlotLib在PyQt4 GUI中绘制一个饼图(i need to plot a piechart in PyQt4 GUI using MatPlotLib)[2023-06-26]
听起来你的问题是,“我怎样才能让饼图坐在我的身影中间?”。 我将回答: 您正在使用QT4窗口系统来制作您的情节这一事实并不特别。 我已经采用了matplotlib饼图示例,并修改了图形宽度以模拟您的要求。 最后,至关重要的是,我将宽高比设置为1:1以保持饼图为圆形: from pylab import * # make a square figure and axes figure(1, figsize=(10, 3)) ax = axes([0.1, 0.1, 0.8, 0.8]) labels = ...