如何在不更改绘图的情况下更改matplotlib中的图形画布大小?

时间:2016-05-25 20:25:08

标签: python matplotlib

我想在matplotlib中使用面板标签(" A"," B",...")注释我正在制作的图表。例如,我想用一个大的" A"来注释一组子图。在图的左上角,如下面的代码所示。我怎样才能改变人物画布来制作这个" A"可见?

 <textarea id="message" name="message" style="width:100%;"></textarea>
 <input value="SEND" style="border-radius: 5px 5px 5px 5px;" type = 'button' onclick = 'ajaxFunction()'/>



<script type="text/javascript">                             <!--
            //Browser Support Code
            function ajaxFunction(){
               var ajaxRequest;  // The variable that makes Ajax possible!

               try {
                  // Opera 8.0+, Firefox, Safari
                  ajaxRequest = new XMLHttpRequest();
               }catch (e) {
                  // Internet Explorer Browsers
                  try {
                     ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                  }catch (e) {
                     try{
                        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                     }catch (e){
                        // Something went wrong
                        alert("Your browser broke!");
                        return false;
                     }
                  }
               }

               // Create a function that will receive data 
               // sent from the server and will update
               // div section in the same page.

               ajaxRequest.onreadystatechange = function(){
                  if(ajaxRequest.readyState == 4){
                     var ajaxDisplay = document.getElementById('chbox');
                     ajaxDisplay.innerHTML = ajaxRequest.responseText;
                  }
               }

               // Now get the value from user and pass it to
               // server script.

               var message = document.getElementById('message').value;
               var queryString = message ;
               ajaxRequest.open("POST", 'chatdata.php', true);
               //ajaxRequest.send(null); 
               ajaxRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
               ajaxRequest.send('queryString');
            }
</script>



<?php
$message1 = $_REQUEST['message'];
echo $message;
?>

how to make room for text label by increasing padding around subplots?

有没有办法添加&#34;填充&#34;在子图的左侧,以便将它们推到图的右侧,而不更改print_r($message);参数?并没有重新调整情节?画布上有足够的空间来贴合标签和子图。

1 个答案:

答案 0 :(得分:5)

添加plt.subplots_adjust()

f = plt.figure(figsize=(5,5))
plt.subplot(2, 2, 1)
# this "A" is clipped in the plot
plt.annotate("A",
             xy = (-0.25, 1.1),
             xytext = (-0.25, 1.1),
             xycoords = 'axes fraction',
             textcoords = 'axes fraction',
             fontsize=30)
plt.subplot(2, 2, 2)
plt.subplot(2, 2, 3)
plt.subplot(2, 2, 4)
plt.tight_layout()
plt.subplots_adjust(top=0.9)
plt.show()

请确保不要在plt.tight_layout之后放置plt.subplots_adjust,因为这会覆盖更改。

另请参阅 this 页面调整子图。

使用上面代码生成的数字如下所示: enter image description here