Sunday, 13 June 2010

Broken axis, once more

I have discussed this subject at least on two occasions, and in fact, most of the present post was already described in one of my very first posts. However, I thought that it might be worthwhile to dust it off, especially, that this is a scientifically relevant feature, which is still missing in gnuplot. But with a bit of work, we can rectify the problem. In short, there are situations, when we just have to break the axis, simply because there is a large gap between two relevant ranges of a plot. Take this example, for instance
plot [0:40] 20.0*atan(x-20.0) + 32 + sin(x)
which would result in the following graph:


The problem is obvious: the function has some interesting modulation close to 0, and close to 60, but it is rather dull between these two extrema. The solution is to cut out the segment between 10, and 60, say.

What we will use is a very handy function in gnuplot 4.4, which lets the user set the position of the graph exactly. In a multiplot, we would usually set the position as
set multiplot 
set size 1, 0.3
set origin 0, 0.5
plot 'foo' using 1:2 

set size 1, 0.2
set origin 0, 0
plot 'bar' using 3:4
which produces two graphs of size 1, 0.3, and 1, 0.2, respectively, and places them in such a way that their bottom left corner is at (0, 0.5), and (0, 0). But when we say "the bottom left corner", we actually mean the whole figure, tic marks, axis labels, everything. This means at least two things. One is that if we want to break the axis using a multiplot, the ranges will not necessarily be proportional on the figure, simply because the size referred to the size of the whole graph, and not only to the plotting area. Second, if the size of the tic labels is different in the two graphs, they will no longer be aligned properly. This would happen, e.g., if we were to plot over the ranges [0:9], and [1000:10009]: the first range requires labels of width 1, while the second labels of width 5, therefore, the second graph would be narrower, and its left vertical axis shifted to the right, at least, as far as the plotting area is concerned.

In gnuplot 4.4, however, one can set the positions of the plots, and not the whole graph. This is achieved by issuing a command similar to this
set lmargin at screen 0.1
which aligns the left vertical axis of the graph with the point that is at screen position 0.1 along the horizontal direction. There are three more margins, rmargin, tmargin, and bmargin, setting the right hand side, the top, and the bottom of the graph. Specifying the plot's corners explicitly removes the above-mentioned problem with the alignments.

Having said this, our script could read as follows
reset
unset key
bm = 0.15
lm = 0.12
rm = 0.95
gap = 0.03
size = 0.75
y1 = 0.0; y2 = 11.5; y3 = 58.5; y4 = 64.0

set multiplot
set xlabel 'Time [ns]'
set border 1+2+8
set xtics nomirror
set ytics nomirror
set lmargin at screen lm
set rmargin at screen rm
set bmargin at screen bm
set tmargin at screen bm + size * (abs(y2-y1) / (abs(y2-y1) + abs(y4-y3) ) )

set yrange [y1:y2]
plot [0:40] 20.0*atan(x-20.0) + 32 + sin(x)

unset xtics
unset xlabel
set border 2+4+8
set bmargin at screen bm + size * (abs(y2-y1) / (abs(y2-y1) + abs(y4-y3) ) ) + gap
set tmargin at screen bm + size + gap
set yrange [y3:y4]

set label 'Power [mW]' at screen 0.03, bm + 0.5 * (size + gap) offset 0,-strlen("Power [mW]")/4.0 rotate by 90

set arrow from screen lm - gap / 4.0, bm + size * (abs(y2-y1) / (abs(y2-y1)+abs(y4-y3) ) ) - gap / 4.0 to screen \
lm + gap / 4.0, bm + size * (abs(y2-y1) / (abs(y2-y1) + abs(y4-y3) ) ) + gap / 4.0 nohead

set arrow from screen lm - gap / 4.0, bm + size * (abs(y2-y1) / (abs(y2-y1)+abs(y4-y3) ) ) - gap / 4.0  + gap to screen \
lm + gap / 4.0, bm + size * (abs(y2-y1) / (abs(y2-y1) + abs(y4-y3) ) ) + gap / 4.0 + gap nohead

set arrow from screen rm - gap / 4.0, bm + size * (abs(y2-y1) / (abs(y2-y1)+abs(y4-y3) ) ) - gap / 4.0 to screen \
rm + gap / 4.0, bm + size * (abs(y2-y1) / (abs(y2-y1) + abs(y4-y3) ) ) + gap / 4.0 nohead

set arrow from screen rm - gap / 4.0, bm + size * (abs(y2-y1) / (abs(y2-y1)+abs(y4-y3) ) ) - gap / 4.0  + gap to screen \
rm + gap / 4.0, bm + size * (abs(y2-y1) / (abs(y2-y1) + abs(y4-y3) ) ) + gap / 4.0 + gap nohead

plot [0:40] 20.0*atan(x-20.0) + 32 + sin(x)

unset multiplot

The first couple of lines specify how big a figure we want to have: bm, lm, and rm are the bottom, left, and right margins, respectively. We also define the size of the gap, which we will have between the two plots. y1 through y4 are the definitions of our plot ranges. In other words, the interval between y2, and y3 will be cut out of our figure.

In the multiplot environment, we set the axes (for the bottom figure on the bottom, left, and right, while for the top figure on the top, left, and right), the axis labels (the vertical label we have to set by hand, for otherwise it would be centred on the vertical axis of the bottom or top figure, but not on the whole), and set the positions of the figures. Note that the definition used for tmargin and bmargin makes sure that the two plotted intervals are proportional. Before plotting the second curve, we also set four small headless arrows, which are meant to represent the break in the axes. It can be left out, if not desired, or they can be replaced by two dashed vertical lines.


This method can also be used, if one wants to plot a single curve or data set, but with logarithmic axis on one interval, and linear on the other.

45 comments:

  1. Thank you! Just what I wanted.

    ReplyDelete
  2. reset
    unset key
    bm = 0.15
    lm = 0.12
    rm = 0.95
    gap = 0.03
    size = 0.75
    y1 = 0.0; y2 = 11.5; y3 = 58.5; y4 = 64.0
    #kk = 0.7 #relative height of bottom plot
    # or to keep proportional scale
    kk = (abs(y2-y1) / (abs(y2-y1) + abs(y4-y3) ) )

    set multiplot
    set xlabel 'Time [ns]'
    set border 1+2+8
    set xtics nomirror
    set ytics nomirror
    set lmargin at screen lm
    set rmargin at screen rm
    set bmargin at screen bm
    set tmargin at screen bm + size * kk

    set yrange [y1:y2]
    plot [0:40] 20.0*atan(x-20.0) + 32 + sin(x)

    unset xtics
    unset xlabel
    set border 2+4+8
    set bmargin at screen bm + size * kk + gap
    set tmargin at screen bm + size + gap
    set yrange [y3:y4]

    set label 'Power [mW]' at screen 0.03, bm + 0.5 * (size + gap) offset 0,-strlen("Power [mW]")/4.0 rotate by 90

    set arrow from screen lm - gap / 4.0, bm + size * kk - gap / 4.0 to screen \
    lm + gap / 4.0, bm + size * kk + gap / 4.0 nohead

    set arrow from screen lm - gap / 4.0, bm + size * kk - gap / 4.0 + gap to screen \
    lm + gap / 4.0, bm + size * kk + gap / 4.0 + gap nohead
    set arrow from screen rm - gap / 4.0, bm + size *kk - gap / 4.0 to screen \
    rm + gap / 4.0, bm + size * kk + gap / 4.0 nohead

    set arrow from screen rm - gap / 4.0, bm + size * kk - gap / 4.0 + gap to screen \
    rm + gap / 4.0, bm + size * kk + gap / 4.0 + gap nohead

    plot [0:40] 20.0*atan(x-20.0) + 32 + sin(x)

    unset multiplot

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Great blog thanks for sharing Searching for a SEO company in Chennai that can bring your brand to the top results page on Google? Look no further - Adhuntt Media, with their team of SEO experts, can make it happen that too for the best value.
    digital marketing company in chennai
    seo service in chennai
    web designing company in chennai
    social media marketing company in chennai

    ReplyDelete
  5. Thanks for this blog are more informative contents in step by step. I here attached my site would you see this blog.

    7 tips to start a career in digital marketing

    “Digital marketing is the marketing of product or service using digital technologies, mainly on the Internet, but also including mobile phones, display advertising, and any other digital medium”. This is the definition that you would get when you search for the term “Digital marketing” in google. Let’s give out a simpler explanation by saying, “the form of marketing, using the internet and technologies like phones, computer etc”.

    we have offered to the advanced syllabus course digital marketing for available join now.

    more details click the link now.

    https://www.webdschool.com/digital-marketing-course-in-chennai.html

    ReplyDelete
  6. Amazing articles useful information.

    Web designing trends in 2020

    When we look into the trends, everything which is ruling today’s world was once a start up and slowly begun getting into. But Now they have literally transformed our lives on a tremendous note. To name a few, Facebook, Whats App, Twitter can be a promising proof for such a transformation and have a true impact on the digital world.

    we have offered to the advanced syllabus course web design and development for available join now.

    more details click the link now.

    https://www.webdschool.com/web-development-course-in-chennai.html

    ReplyDelete
  7. Thank you for your attention to detail and great writing style. Your professionalism shows in your article. I like your interesting views and Best Data Science training in Mumbai

    Data Science training in Mumbai
    appreciate your unique ideas. This is quality.

    ReplyDelete
  8. So far, I agree with you on much of the info you have written here. I will have to think some on it, but overall this is a wonderful article.
    SAP training in Kolkata
    SAP training Kolkata
    Best SAP training in Kolkata
    SAP course in Kolkata
    SAP training institute Kolkata

    ReplyDelete
  9. Thanks for this very helpfull trick.
    What would be the easiest way to decrease the width of the whole graph ? Say, if you are plotting very flat curves and you want to make them appear further appart from each other.

    ReplyDelete
  10. As a matter of fact, the Internet's "timewarping" is both its weakness and its strength. The trick is to use it correctly. I started to send students my lessons in email. machine learning training in hyderabad

    ReplyDelete
  11. I would like to say thank you for the amazing details and concepts you are sharing in this.The style of writing is excellent and also the content is top-notch. Thanks for that shrewdness you provide the readers! to read. I never stop myself to say something about it. You’re doing a great job. Keep it up...


    Robotic Process Automation (RPA) Training in Chennai | Robotic Process Automation (RPA) Training in anna nagar | Robotic Process Automation (RPA) Training in omr | Robotic Process Automation (RPA) Training in porur | Robotic Process Automation (RPA) Training in tambaram | Robotic Process Automation (RPA) Training in velachery

    ReplyDelete
  12. I wish that I could take an idea, research it like you and put it on paper in the same fashion that I have just read. Your ideas are fantastic.
    Data Science training in Mumbai
    Data Science course in Mumbai
    SAP training in Mumbai

    ReplyDelete
  13. Your article has piqued my interest. This is definitely a thinker's article with great content and interesting viewpoints. I agree in part with a lot of this content. Thank you for sharing this informational material.
    SAP training in Kolkata
    SAP training Kolkata
    Best SAP training in Kolkata
    SAP course in Kolkata

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete

  15. Thanks for the Valuable information.Really useful information. Thank you so much for sharing. It will help everyone.

    SASVBA Delhi provides extensive MERN stack training in Delhi. The extensive hands-on session, hosted by the MERN Stack Training Institute in Delhi, includes live projects and simulations.

    FOR MORE INFO:

    ReplyDelete
  16. It is a pleasure to read such honest and thoughtful content. I'm glad you bought this gift for me, as it's inspiring and help me to work harder daily!
    Data Science Training in Hyderabad
    Data Science Course in Hyderabad

    ReplyDelete
  17. Thanks! I agree, your article is incredibly useful and no doubt you've done a lot of research to present this information - hopefully you can post some more material related to this topic in the future.
    AWS Training in Hyderabad
    AWS Course in Hyderabad

    ReplyDelete
  18. Who is the best Social Media Marketing Expert in Meerut?

    Rashmi Rathi at Techdost Services Private Limited is the best Social Media Marketing Expert in Meerut delivering high-quality, reliable and trustworthy social media marketing services in Meerut. Contact a leading social media marketing expert in Meerut, Rashmi Rathi.
    Social Media Marketing Expert in Meerut

    Who is the best Android App Developer in Meerut?

    Sandeep Sharma at Techdost Services Private Limited is a leading and renowned Android App Developer in Meerut delivering high-quality Android app development services all over Meerut, India.
    Contact at +91-7500996633 or Mail us at Info@techdost.com
    Android App Developer in Meerut
    Android App Developer in Meerut

    ReplyDelete
  19. Amazing post! Your post is very useful, and I think it very interesting while reading it.
    Digital VoIP Gateway
    GSM 3G LTE Gateway

    ReplyDelete
  20. Incredible post I should say and a debt of gratitude is in order for the data. Schooling is certainly a tacky subject. Be that as it may, is still among the main subjects within recent memory. I appreciate your post and anticipate more. You have made some valid statements there. I looked on the web to study the issue and discovered a great many people will oblige your perspectives on this site...
    how to make a paper airplane eagle | how to make a boomerang airplane | the eagle paper airplane | best paper airplane design for distance and accuracy | best paper airplanes for distance and speed | what is the best paper airplane design for distance | paper airplane that flies far and straight | nakamura lock paper airplane instructions

    ReplyDelete
  21. It is perfect chance to make a couple of game plans for the future and the opportunity has arrived to be sprightly. I've scrutinized this post and if I may I have the option to need to suggest you some interesting things or recommendations. Perhaps you could create next articles insinuating this article. I have to examine more things about it!

    ReplyDelete
  22. 360DigiTMG, the top-rated organisation among the most prestigious industries around the world, is an educational destination for those looking to pursue their dreams around the globe. The company is changing careers of many people through constant improvement, 360DigiTMG provides an outstanding learning experience and distinguishes itself from the pack. 360DigiTMG is a prominent global presence by offering world-class training. Its main office is in India and subsidiaries across Malaysia, USA, East Asia, Australia, Uk, Netherlands, and the Middle East.

    ReplyDelete
  23. Are you searching for good Data Science training in Bangalore to upscale your skills to dominate the job market? 360DigiTMG will help you realize it. Get trained by efficient professionals with real-time projects and assignments in your training and bag your desired job. Enroll now!!

    Data Science Course in Jaipur

    ReplyDelete
  24. i'd subsequent to to make regarded that this blog clearly satisfied me to take steps it! thanks, each and each one fine reveal... Keymaker Bandicam

    ReplyDelete
  25. tremendous article, thank you for putting this collectively! this is obviously one allowable publicize. thanks for the important advice and insights you have as a end result furnished right here..... Download Microsoft Office 2010 Full Crack + Keygen

    ReplyDelete
  26. it is good course contant .It is very so much valuable content. I hope these Commenting lists will help to my website
    Azure Data Factory course in hyderabad
    Azure Data Engineer Training Online Hyderabad
    azure training in hyderabad ameerpet
    Azure Data Factory online Training in Hyderabad
    Microsoft Azure Data Factory in hyderabad

    ReplyDelete
  27. Learn the fundamentals of Data Science and master the skills to handle epic amounts of data collected by organizations today. Gain expertise in organizing, analyzing, and transforming data to uncover its hidden power. Drive your career forward with a Data Science course in Bangalore and learn to uncover insights to present critical findings using visualization tools. Not only this, avail the best-in-class content delivered by stellar faculty who use a blended approach of theory as well as practical knowledge to ensure all the concepts are crystal clear.


    Data Science Course in Delhi

    ReplyDelete


  28. I sincerely appreciate you taking the time to write such a useful essay. I sincerely hope you'll continue since there is no limit to the quantity of knowledge that is out there.
    DigiDNA iMazing Activation Key

    ReplyDelete

  29. I appreciate the inclusion of best practices for data cleaning and preprocessing in this article.
    data analyst institute in hyderabad

    ReplyDelete
  30. The practical advice shared in this blog post for building a career in data science is invaluable.data scientist course in hyderabad

    ReplyDelete