Seaborn despine有两个y尺度(twinx)

时间:2016-05-26 12:52:05

标签: python matplotlib seaborn

如何让import matplotlib.pyplot as plt import seaborn as sns import numpy as np sns.set_style("white") fig, ax = plt.subplots() ax.plot(np.random.rand(10)) ax2 =ax.twinx() ax2.plot(100*np.random.rand(10)) sns.despine(ax=ax, right=True, left=True) sns.despine(ax=ax2, left=True, right=False) 不将我的两个音阶放在我的情节的左侧? 我到目前为止所提出的最好的是:

function paypalPaymentViaStoredCreditCard_post()
{
    $access_token = "XXXXXXXX";
    $ch = curl_init();
    $data = '{
        "intent": "sale",
        "payer": {
          "payment_method": "credit_card",
          "funding_instruments":[
            {
              "credit_card_token": {
                "credit_card_id": "CARD-6F0009583J819301DK5DO5JA",
                "payer_id": "BAAAA"
              }
            }
          ]
        },
        "transactions":[
          {
            "amount":{
            "total":"100.00",
            "currency":"USD"
            },
            "description": "This is the payment transaction description."
          }
        ]
      }';


     curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     "Content-Type:application/json",
     "Authorization: Bearer " . $access_token,
     "Content-length: " . strlen($data))
     );


    curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Some-Agent/1.0");
    $result = curl_exec($ch);
    print_r($result);die;
    if (empty($result)) die("Error: No response.");
    else {
          $json = json_decode($result);
          print_r($json);
          die;
          return $json;
    }
    curl_close($ch);
} 

但是任何其他组合都不会使y轴脱垂或将右轴放在左侧。

上述输出:(所需输出没有刺,只是左右数字)

enter image description here

1 个答案:

答案 0 :(得分:6)

我想那就是你想要的。

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

sns.set_style("white")

fig, ax = plt.subplots()
ax.plot(np.random.rand(10))
ax2 =ax.twinx()
ax2.plot(100*np.random.rand(10))
sns.despine(ax=ax, right=True, left=True)
sns.despine(ax=ax2, left=True, right=False)
ax2.spines['right'].set_color('white')

no spines, just numbers on left and right